Reputation: 1792
I have the following query:
SET @q = 12;
UPDATE `table`
SET qty = CONCAT(GREATEST(qty - @q, 0), LEFT(@q := @q - LEAST(qty, @q), 0))
ORDER BY id;
(Go vote eggyal up for the great query here: Removing a quantity from multiple rows in a database )
I am running the query (without preparing in this case) through OOP PDO / MySQL.
I want to pass the value of the @q back to PHP or any flag really if @q did not get to 0. I'm not sure how to accomplish this. If anyone is able to point me in the right direction, I'd appreciate it.
Thanks
Upvotes: 1
Views: 172
Reputation: 360572
Just select it, as you would anything else:
$res = mysql_query("SELECT @q AS q") or die(mysql_error());
$row = mysql_fetch_assoc($res);
echo $row['q'];
Upvotes: 1
Reputation: 80629
Doesn't this work:
$res = mysql_fetch_array( mysql_query( "SELECT @q" ) );
print_r( $res );
Upvotes: 1