With the mysqli extension for PHP, I could use a method fetch_field()to get the unaliased names for columns and tables through orgnameand orgtableas a result. PDO provides a method getColumnMeta(), but does not contain information about the original names of tables and columns; it returns only aliases.
Are there any alternatives to getting this information using PDO? I was thinking about parsing information from an SQL query, but I hope there are more beautiful solutions ...
SELECT id AS col1, session AS col2 FROM sessions AS table1;
Results using PDOStatement::getColumnMeta():
Array
(
[native_type] => LONG
[flags] => Array
(
[0] => not_null
[1] => primary_key
)
[table] => table1
[name] => col1
[len] => 10
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => VAR_STRING
[flags] => Array
(
[0] => not_null
[1] => unique_key
)
[table] => table1
[name] => col2
[len] => 32
[precision] => 0
[pdo_type] => 2
)
source
share