在php里写sql查询需要注意的事情

---恢复内容开始---

今天往php里写了一条sql查询,

$sql = "select * from videos where vuser=".$u;

$ret = mysql_query($sql,$con);

while($row = mysql_fetch_array($ret))『』

然后运行时在while语句处卡住了,最后检查nginx的error.log,提示是这样的"[error] 16246#0: *28 FastCGI sent in stderr: "PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /usr/local/openresty/nginx/html/list.php on line 14" while reading response header from upstream"

后来发现原来是$sql出现了问题,查询varchar类型语句后面不能直接接.$变量,$变量在php里不是一个字符串类型.

最后改成了$sql = "select * from videos where vuser='".$u."'";,程序运行通过。

---恢复内容结束---

原文地址:https://www.cnblogs.com/cyberwalker/p/3629142.html