mysql SELECT * WHERE value = $row['item'] [英] mysql SELECT * WHERE value = $row['item']

查看:68
本文介绍了mysql SELECT * WHERE value = $row['item']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码的正确方法是什么

What's the correct way to code the following

SELECT * FROM table WHERE value = $row['item']

$row['item'] 正确回显,但在 mysql 查询中似乎不起作用.被这个问题困扰了几天.我试过 .$row['item']. 和其他一些变体,但我一定是做错了什么.

$row['item'] echos correctly, but does not seem to work in the mysql query. Been having this problem for a few days. I've tried .$row['item']. and a few other variations but I must be doing something wrong.

推荐答案

更好更合适的方法是使用 mysqli 和准备好的语句,即:

The better more appropriate approach is to use mysqli and prepared statements ie:

$stmt = $mysqli->prepare("SELECT * FROM table WHERE value =?");
$stmt->bind_param("s",$row['item']);  // I am assuming row['item'] is a string
$stmt->execute();

如果你不能使用mysqli或者绝对拒绝你可以使用这个:

If you can't use mysqli or absolutely refuse to you can use this:

$query = "SELECT * FROM table WHERE value = '".mysql_real_escape_string($row['item'])."'"; 

这篇关于mysql SELECT * WHERE value = $row['item']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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