php UNION problem

First of all I want to say Hi to all.

I have a strange problem with sql query in php.
I’m using PDO to connect with MySQL database. A query:

“SELECT o.* FROM table1 o UNION SELECT o.* FROM table2 o LEFT JOIN table3 d ON o.field1 = d.field1 ORDER BY field2 ASC”

doesn’t work in php.

When I using this query in PHPMyAdmin it works fine.
Any suggestions would be very appreciated.

Thanks in advance,

Kris

Something isn’t correct. Do you have PDO exception modes on? By default they hide exceptions.

[php]$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);[/php]

Everytime I see someone using Union their database design is wrong. Post your DB schema. The database design needs to be right before you write any code.

That are perfectly valid times to use union, just because you haven’t seen proper usage does not mean that it is a design issue.

On Help forums with inexperienced posters it has always been the wrong DB design. Best thing is for the OP to post his DB schema.

Sponsor our Newsletter | Privacy Policy | Terms of Service