MySQL 功能不工作 [英] MySQL function not working

查看:53
本文介绍了MySQL 功能不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做

SELECT count(*) FROM table_name WHERE id= 2

代码有效,但当我这样写时:

The code works but when I write it like this:

$try= 2;
SELECT count(*) FROM table_name WHERE id= $try; 

代码不再起作用.有人可以解释一下吗?

The code doesn't work anymore. Can someone please explain?

推荐答案

首先,您必须将参数正确地包含"到字符串中

First of all you have to "include" your parameter properly into string

'SELECT count(*) FROM tble_name WHERE id='.$try; 

其次,你必须把它传递给mysqli对象

Second, you have to pass it to mysqli object

$result = $mysqli->query('SELECT count(*) FROM tble_name WHERE id='.$try);

然后你必须获取结果

while ($row = $result->fetch_row()) {
        /* your logic here */
    }

显然,您必须正确创建新的 mysqli 对象,如我提供给您的链接中所述.

Obviously you have to create new mysqli object properly, as explained into link that I've provided you.

这篇关于MySQL 功能不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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