dqyz48470 2010-02-19 21:46
浏览 39
已采纳

PHP:传递mysql查询的变量而不将它们包含在“或”中

There's an open source application that does queries like so:

$db->query('SELECT item FROM table WHERE something='.$something);

This works fine, mysql runs the query however if I use exactly the same method I get an error, mysql is seeing it as "something = (value of $something)" and it's (rightly) complaining that (value of $something) is not a row. These applications both run on the same server and I've rooted through their code for hours but I cannot work out what is causing it.

$db->query('SELECT item FROM table WHERE something='.$something);

works in their application but fails in mine. Do I need to do something with the string I'm passing? I have no problem enclosing the variables properly, like:

$db->query('SELECT item FROM table WHERE something="'.$something.'"');

but I'd like to know what causes the difference.

  • 写回答

4条回答 默认 最新

  • doubingjian2006 2010-02-19 21:49
    关注

    MySQL needs the string to be enclosed. The only thing I can think is that $something is an integer or a float.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大