dongzhuang6177 2012-12-27 01:30 采纳率: 100%
浏览 1900
已采纳

求助:SQL语法错误'LIMIT 0,10'

在试图访问我的网站时,我遇到了这个错误:“您的sql语法出现了错误;请检查与MySQL服务器版本相对应的手册,以便在第1行使用‘限制0,10’的正确语法。”

我的第一行是:<?php require_once('Connections/blog.php'); ?>

但似乎这个错误是从这里来的:

$maxRows_getDisplay = 10;
$pageNum_getDisplay = 0;
if (isset($_GET['pageNum_getDisplay'])) {
  $pageNum_getDisplay = $_GET['pageNum_getDisplay'];
}
$startRow_getDisplay = $pageNum_getDisplay * $maxRows_getDisplay;

mysql_select_db($database_blog, $blog);
$query_getDisplay = "SELECT news.title, news.pre,  
 DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
 FROM news ORDER BY news.updated DESC LIMIT 2";
$query_limit_getDisplay = sprintf("%s LIMIT %d, %d", 
 $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay);
$getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error());
$row_getDisplay = mysql_fetch_assoc($getDisplay);

如果你有什么想法,请告诉我,因为我完全懵了。

  • 写回答

1条回答 默认 最新

  • douwo1862 2012-12-27 01:31
    关注

    You have created an SQL statement with two LIMIT clauses, which is not allowed.

    This example shows how difficult it is to debug SQL by staring at the code you use to build up a SQL string.

    It's much easier if you can output the final SQL string to debug it.

    $query_getDisplay = "SELECT news.title, news.pre,  
     DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
     FROM news ORDER BY news.updated DESC LIMIT 2";
    $query_limit_getDisplay = sprintf("%s LIMIT %d, %d", 
     $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay);
    error_log("What's wrong with this SQL?  " . $query_limit_getDisplay);
    $getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error());
    

    You'll see in your error log:

    What's wrong with this SQL?  SELECT news.title, news.pre,  
    DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted 
    FROM news ORDER BY news.updated DESC LIMIT 2 LIMIT %d, %d
    

    And that makes it much easier to spot invalid SQL syntax (assuming you can recognize valid vs. invalid SQL syntax).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题