MySQLi语法错误,但没有第114行

时间:2013-06-14 00:41:47

标签: php mysql mysqli

我收到以下错误

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近''第114行

但我的代码只有27行

<?php
    $DB_NAME = 'QCSYSTEM';
    $DB_HOST = 'monitor';
    $DB_USER = 'QCSYSTEM';
    $DB_PASS = '247#Direct';
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    // A QUICK QUERY ON A FAKE USER TABLE
    $query = "SELECT username FROM `users` WHERE";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);

    // GOING THROUGH THE DATA
    if($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo stripslashes($row['username']);    
        }
    }
    else {
        echo 'NO RESULTS';  
    }
// CLOSE CONNECTION
mysqli_close($mysqli);
?>

2 个答案:

答案 0 :(得分:1)

$query = "SELECT username FROM `users` WHERE";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

您没有指定where子句,因此查询失败。

答案 1 :(得分:1)

您缺少在此处说明WHERE条款

$query = "SELECT username FROM `users` WHERE";

删除它

$query = "SELECT username FROM `users`";

或应用任何条款

$query = "SELECT username FROM `users` WHERE column = 'something'";