Multiple statements in PDO

Hitting a brick wall here. Need to set a SQL var.

SET @itemBalance := 0;
SELECT ... #rest of the sql query.

And then run the PHP select statement. PDO doesn’t allow multistatements, so how is this to be done?

You can use transactions to initiate multiple statements.

Ja, knew about that. I figured out how to get it to work

$this->pdo->query(“SET @itemBalance = 0”);

That will init the variable for the remainder of the connection’s lifespan, so I don’t have to try to put it in the same statement per say (or even the same transaction.

Transactions are invaluable, but they are necessary overhead when doing read queries. Write queries though - don’t leave home without them.

Why that wasn’t working earlier is because to get the variable to have the expected effect I have to select from a select, which is a wild trick I’ve not done before. More on that in the appropriate thread in the SQL forum.