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

查看:93
本文介绍了mysql SELECT * WHERE值= $ 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值= $ row ['item']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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