Re: PDO include table name prefixes in FETCH_ASSOC
| From: | Aaron Paetznick | Date: | Wed, 24 Mar 2010 18:04:04 +0000 |
| Subject: | Re: PDO include table name prefixes in FETCH_ASSOC | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-47006@lists.php.net to get a copy of this message | ||
Thanks for the advise. I wanted a more automatic method of prefixing column names, but I ended up just aliasing them all.
I know I could always just issue multiple SELECTs, but I wish MySQL would support this sort of functionality natively. I'd really like to reference my results as $result["table0"]["column0"] from a single SELECT.
Anyways, thanks all.
--Aaron
On 3/24/2010 11:28 AM, Niel Archer wrote:
Many of my MySQL tables have columns with the same name. I want to have PDO include table names in named result sets. For example:Sounds like you want to UNION two SELECTs http://dev.mysql.com/doc/refman/5.0/en/union.html (SELECT col1, col2, col4 FROM table1 WHERE ... ORDER BY ...) UNION (SELECT col1, col2, col4 FROM table2 WHERE ... ORDER BY ...)$sth = $dbh->prepare("SELECT * FROM table0, table1"); $result = $sth->fetchAll(PDO::FETCH_ASSOC);I want $result to be organized like:echo $result["table0.column0"]; echo $result["table0.column1"]; echo $result["table1.column0"]; echo $result["table1.column1"];Or, alternatively:echo $result["table0"]["column0"]; echo $result["table0"]["column1"]; echo $result["table1"]["column0"]; echo $result["table1"]["column1"];Any ideas? Thanks!--Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- Niel Archer niel.archer (at) blueyonder.co.uk