sql查询执行出现问题
我在执行 sql 查询时遇到问题。我正在使用此 sql 查询:
$userid = 1;
$sql = mysql_query("
SELECT ID, Nm, Address, date_format(DateOfBirth, '%d%M%Y') as DateOfBirth
FROM PersonalDetails where UserMasterID = $userid
") or die (mysql_error());
结果显示为:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 '= 附近使用的正确语法 ' 在第 1 行当
我在 PHPMyAdmin 中执行此操作时,它可以正常工作。 我正在使用 mysql(5.0.5b) 和 PHP (5.2.6)
你能帮我吗?
I have a problem in sql query execution.I am using this sql query:
$userid = 1;
$sql = mysql_query("
SELECT ID, Nm, Address, date_format(DateOfBirth, '%d%M%Y') as DateOfBirth
FROM PersonalDetails where UserMasterID = $userid
") or die (mysql_error());
The result appears as:
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 '=
' at line 1
When I execute this in PHPMyAdmin it works properly.
I am using mysql(5.0.5b) and PHP (5.2.6)
Can you help me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果
UserMasterID
不是整数,您可能需要在值两边加引号:您上面引用的查询与您在 phpMyAdmin 中运行的查询不相同。它包含一个 PHP 变量。
当遇到 SQL 问题时,始终输出并分析解析查询(其中不引用 PHP 变量)。
90%的问题都可以通过这种方式发现并解决。
If
UserMasterID
is not an integer, you may need to put quotes around the value:The query you are quoting above is not identical to what you run in phpMyAdmin. It contains a PHP variable.
When in SQL trouble, always output and analyze the parsed query (with no references to PHP variables in them).
90% of problems can be spotted and solved that way.
如果它在 PHPMyAdmin 中正确运行,但在 PHP 代码中运行不正确,那么对我来说,这表明 PHPMyAdmin 正在执行其著名的任务,即转义和清理它可能执行的所有操作。
将您的代码更改为此并检查它。
它现在应该运行了。
If it runs correctly in PHPMyAdmin, but not in the PHP code, then that says to me that PHPMyAdmin is performing it's famous task of escaping and sanitizing everything it possibly can.
Change your code to this and check it.
It should run now.
呃——你为什么不串联起来呢?
但约瑟夫是当场...
Ehhh - why don't you concatenate ?
but Joseph is spot on ...