将sql变量返回给PHP [英] Returning a sql variable to PHP

查看:55
本文介绍了将sql变量返回给PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

    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 )

我正在通过OOP PDO/MySQL运行查询(在这种情况下无需准备).

I am running the query (without preparing in this case) through OOP PDO / MySQL.

如果@q未达到0,我想将@q的值真正传递回PHP或任何标志.我不确定如何完成此操作.如果有人能够指出正确的方向,我将不胜感激.

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.

谢谢

推荐答案

只需选择它,就像其他任何操作一样:

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'];

这篇关于将sql变量返回给PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆