When I use fetchAll
to get an entire column into an array my code does fetch the first two columns and puts these into an array. However when I try to do this with the final third column it gives me an blank array my code is as follows.
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test"; // Table name
// Connect to server and select databse.
$con = new PDO('mysql:host=localhost;dbname=test', $username, $password );
// username and password sent from form
$sth = $con->prepare("SELECT range FROM test");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>
Now when we replace range for instead nr I get this output
Fetch all of the remaining rows in the result set: Array ( [0] => Array ( [nr] => 1 [0] => 1 ) [1] => Array ( [nr] => 2 [0] => 2 ) [2] => Array ( [nr] => 3 [0] => 3 ) [3] => Array ( [nr] => 4 [0] => 4 ) )
However when we leave range as it is we get
Fetch all of the remaining rows in the result set: Array ( )