I have the following two tables:
foo:
ID NUMBER(38)
DATA VARCHAR2(10)
bar:
ID NUMBER(38)
FOO_ID NUMBER(38)
DATA VARCHAR2(10)
When using PDO to issue the following query:
SELECT * FROM foo f INNER JOIN bar b ON (f.id = b.foo_id)
Is there any way to get back all of the columns from the join in some kind of auto-aliased format (e.g. "FOO.ID", "FOO.DATA", "BAR.ID", etc.) so that I don't need to specify and alias every single column in the query?
I've read all of the documentation on the various fetch modes, and experimented with most of the flags/options, but still can't seem to find what I'm looking for.
Update:
Using PDO::FETCH_ASSOC, the columns from foo seem to be overwritten by the columns from bar:
array(3) {
["ID"]=>
string(1) "1"
["DATA"]=>
string(5) "bar 1"
["FOO_ID"]=>
string(1) "1"
}
Using PDO::FETCH_NUM, the columns from both foo and bar appear, in order, but without any way to identify which columns came from which tables, except by knowing the number of columns in each table and exact order of those columns (error prone):
array(5) {
[0]=>
string(1) "1"
[1]=>
string(5) "foo 1"
[2]=>
string(1) "1"
[3]=>
string(1) "1"
[4]=>
string(5) "bar 1"
}
Using PDO::FETCH_BOTH, we seemingly run into the same problems as PDO::FETCH_ASSOC and PDO::FETCH_NUM combined, and create a horribly unintelligible result set:
array(8) {
["ID"]=>
string(1) "1"
[0]=>
string(1) "1"
["DATA"]=>
string(5) "bar 1"
[1]=>
string(5) "foo 1"
[2]=>
string(1) "1"
["FOO_ID"]=>
string(1) "1"
[3]=>
string(1) "1"
[4]=>
string(5) "bar 1"
}
IDEALLY, the result set should look similar to this:
array(5) {
["FOO.ID"]=>
string(1) "1"
["FOO.DATA"]=>
string(5) "foo 1"
["BAR.ID"]=>
string(1) "1"
["BAR.FOO_ID"]=>
string(1) "1"
["BAR.DATA"]=>
string(5) "bar 1"
}