Use mysql SET variables in db_query How can I use mysql SET variables while using my PDO queries?

db_query('SET @x := 5,SET @y := 6, SELECT * from mytable')-&gt;fetchAll();


I have tried this and many variations of this statement with and without ':' etc, but it doesn't work.
There are 2 points here.

SET @x := 5,SET @y := 6, SELECT * from mytable" should be "SET @x := 5,SET @y := 6; SELECT * from mytable


as

SET @x := 5,SET @y := 6;" and "SELECT * from mytable


are 2 separate MySQL statements.

You can not execute multiple statements together using db_query(). Since the PHP functions mysql_query() and mysqli_query() can only execute one SQL statement, the db_query() wrapper can also only execute one SQL statement.

What you can do here is, divide that into two part and run it.

db_query('SET @x := 5,SET @y := 6;')-&gt;execute();
db_query('SELECT * from mytable')-&gt;fetchAll();