I'm looking for a way to get the field name from the column index returned by a SELECT query using PDO. What I'm looking for is an equivalent to
mysql_field_name(resource $result, int $field_offset)
The PHP documentation says the above function is deprecated as of PHP 5.5.0 and the alternative they suggest for PDO is considered experimental and the behavior of it may change without notice. That doesn't sound like something I would want in my application.
I also do not want to query the MySQL system tables to get the columns since that just would not be efficient.
If the results of the fetchAll() function returns the resulting array below, is there a way I can retrieve the value of the column name (which equals "NAME" below) by specifying the column index?
Array
(
[0] => Array
(
[NAME] => pear
[0] => pear
[COLOUR] => green
[1] => green
)
[1] => Array
(
[NAME] => watermelon
[0] => watermelon
[COLOUR] => pink
[1] => pink
)
)
Aucun commentaire:
Enregistrer un commentaire