Using 'OR' PDO query

Hi, sorry moving from mysqli…erm, what can i do to get this work?

$opt1 = $pdo->query("SELECT menu1.cat FROM menu1 WHERE (menu1.cat = 'x' OR menu1.cat = 'y' OR menu1.cat = 'z'" );

(values specified, rather than string)

There seems nothing wrong with that query. Otherwise please explain what your problem is.

You are missing a closing bracket in the query string.

Ah, thanks…well spotted!, i thought there was an issue with the PDO query, as apposed to dumb ass omission :slight_smile:

The actual query strings are no different with PDO.
Alternatively you could use an IN clause for this.

"SELECT menu1.cat FROM menu1 WHERE menu1.cat IN ('x', 'y', 'z')"

That did cause a MySQL error. If you had PDO’s error reporting enabled, you would have seen this issue immediately.

2 Likes

How to do it:

1 Like

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