is there a way of getting table name for each column in a postgre result in PHP?
Imagine you hav开发者_开发问答e a select with join, for example:
$Q = <<<E2OD
SELECT * FROM user U
LEFT JOIN department D ON U.department_id = D.id
E2OD;
In PHP/FirebirdSQL:
$R = ibase_query($Q);
$D = ibase_fetch_row($R);
$info = ibase_field_info($R, 0);
Returns
Array
(
[0] => id
[name] => id
[1] => id
[alias] => id
[2] => user
[relation] => user
[3] => 8
[length] => 8
[4] => BIGINT
[type] => BIGINT
)
While in PHP/PostgreSQL:
$select = $DB->query($Q);
$meta = $select->getColumnMeta(0);
Returns
Array
(
[pgsql:oid] => 20
[native_type] => int8
[name] => id
[len] => 8
[precision] => -1
[pdo_type] => 2
)
As you see, there's no information about the table the column is from. There's a missing key [relation] => user
or similar displaying the table name.
http://php.net/manual/en/pdostatement.getcolumnmeta.php
Can PHP get this information with it's PG or PDO libraries? Does PostgreSQL provide this information to client libraries? What needs to be done to make this happen?
Thanks for any hint,
Michal
Check pg_field_table().
精彩评论