I have a question about PDO in PHP:
I'm trying to fetch a column from my mysql database, indexed by the id of each row... Now php.net has an example on how to do it: http://www.php.net/manual/en/pdostatement.fetchall.php (example #3)
<?php
$insert = $dbh->prepare("INSERT INTO fruit(name, colour) VALUES (?, ?)");
$insert->execute(array('apple', 'green'));
$insert->execute(array('pear', 'yellow'));
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* Group values by the first column */
var_dump($sth->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
?>
But this doesn't seem to work for me... All i get is:
array {
[id1] => null;
[id2] => null;
[id3] => null;
...
}
Even when i copy the exact same code, and only edit the table name etc. Does anyone know what can cause this problem?
$insert->execute(...)statements return?echo $sth->errorCode();produce anything?