【发布时间】:2012-01-15 01:46:40
【问题描述】:
使用 PHP 的 mysqli 扩展,我可以使用 fetch_field() 方法通过 orgname 和 orgtable 在结果中获取列和表的原始(非别名)名称。 PDO 提供了方法getColumnMeta(),但没有提供有关原始表和列名的信息;它只返回别名。
是否有其他方法可以使用 PDO 获取此信息?我一直在考虑从 SQL 查询中解析信息,但我希望有更漂亮的解决方案...
SELECT id AS col1, session AS col2 FROM sessions AS table1;
使用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
)
【问题讨论】:
-
根据文档,调用
PDOStatement.getColumnMeta的结果包括一个“表”列,其中包含“数据库返回的该列的表的名称”。这不是你在实践中看到的吗? -
我将结果添加到我的帖子中!
-
@d.hill 你找到解决办法了吗?