select查询不会执行,是我的语法错了吗?

时间:2015-11-02 03:51:10

标签: mysql select

显然我有错误,因为这个查询不会执行,任何人都可以看到原因吗?

$username=username;

$mysqli = @new mysqli($localhost, $user, $pass, $database);
$sql = "SELECT * FROM player_log WHERE user = '$username'AND log_status=online";
$result = $mysqli->query($sql);

if ($result->num_rows > 0){
echo "its works";

}

1 个答案:

答案 0 :(得分:1)

多个问题见下面的修改代码

添加了调用mysqli的标准方法($username之后的空格不是问题)

$username=username;

$mysqli = @new mysqli($localhost, $user, $pass, $database);
$sql = "SELECT * FROM player_log WHERE user = '$username'AND log_status='online' ";

if ($result = $mysqli->query($sql)){

    printf("Select returned %d rows.\n", $result->num_rows);

    /* free result set */
    $result->close();
    echo "its works";
}