Compound Queries with PDO

Converting all queries on an older site to PDO. Getting along pretty good, but there’s a compound query or two that I’m puzzling over:

For example, how to handle this?

$sql = “UPDATE tbl1 SET password = (SELECT password FROM tbl2 WHERE user_id = tbl1.user_id AND password <> ‘’ limit 1)”;

AFAIK, there shouldn’t be an issue with using subqueries with PDO. What issue are you running into?

Scott

Perhaps the problem is with the limit 1 which is not standard SQL and so will only work with mySQL whereas PDO is used to make the calls more generic as to the type of database used.

Good spot, maybe using DISTINCT instead would solve the issue?

There’s no reason why LIMIT 1 should be causing any problems. PDO is not made to disallow non standard SQL and all SQL dialects should work without problems. The root of the problem must be elsewhere - we need more info from the OP - what errors he gets and how he issues the query.

WHERE user_id

shouldn’t it be tbl1.user_id?

Provided the database is mySQL - but the OP didn’t say what database they are using so it could be any that PDO support.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.