mysql 查询(如)和 php 的问题
我正在尝试使用类似 sql 的语句,但不幸的是每次使用查询时都会出现错误。在 php 文件中我有:
$b = "SELECT Nombre, Link, Img_Pre, Precio, Descripcion, ID, Categoria, Subcategoria
FROM Productos WHERE Nombre LIKE \"%$a%\"";
但我收到此错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 '\"%THE VALUE OF A%\"' 附近使用的正确语法
如果我在 phpmyadmin 上尝试相同的语句,则不会出现任何错误。为什么使用 php 时会出现此错误?
谢谢!
i'm trying to use the statement like of sql but unfortunately I get an error every time I use the query. In a php file I have:
$b = "SELECT Nombre, Link, Img_Pre, Precio, Descripcion, ID, Categoria, Subcategoria
FROM Productos WHERE Nombre LIKE \"%$a%\"";
but i get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\"%THE VALUE OF A%\"' at line 1
If i try the same statement on phpmyadmin i don't have any error. Why with php I get this error?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的
LIKE
字符串中使用单引号(我相信 phpMyAdmin 在运行查询之前会神奇地将其转换为单引号):确保您已使用
$a
转义code>mysql_real_escape_string() 也是如此,因为它可能会通过引入未转义的引号来破坏您的查询!Use single quotes in your
LIKE
string instead (I believe phpMyAdmin magically converts that to single quotes for you before running the query):Make sure you've escaped
$a
usingmysql_real_escape_string()
too, because it might be breaking your queries by introducing unescaped quotes!尝试:
如果不使用撇号作为字符串分隔符,某些 SQL 查询会发出嘎嘎声
Try:
Some SQL queries will croak if you don't use apostrophes as the string delimeter