Re: [PHP-DB] PDO include table name prefixes in FETCH_ASSOC

[email protected] (Niel Archer)
Newsgroups php.db
Message-ID <[email protected]>
> 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:
> 
>    $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!

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 ...)


> --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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.