我的MySql查询有什么问题?
问题描述:
这是一个查询我使用PHP
的MySQL这样做是查询线我的MySql查询有什么问题?
<?php
$query = "SELECT * FROM node WHERE type = 'student_report' AND uid = '{$uid}' LIMIT 1 ORDER BY created DESC";
?>
我收到以下错误
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 'ORDER BY created DESC' at line 1
答
你需要最后有限制条款。
答
打印整个SQL查询($query
),不仅$uid
,也是LIMIT
条款后order by
答
您的查询应该是:
$query = "SELECT * FROM node WHERE type = 'student_report' AND uid = $uid ORDER BY created DESC LIMIT 1";
你应该在使用SQL预处理语句的习惯查询。 – 2010-03-09 02:42:33