连接MySQL数据库错误

Mir*_*rne 2 php mysql sql

嗨我正在尝试从Mysql服务器加载数据库并继续收到此错误mysqli_num_rows()期望参数1为mysqli_result,布尔值在第15行的C:\ Users\Mirne\Desktop\Server\root\funkcie.php中给出.我检查了很少的帖子,但我没有发现我的错误.Ty求助

<?php
global $X,$Y,$height,$weight,$key,$type,$text,$position;

function load() {
$servername = "localhost";
$username = "root";
$password = "xxxx";
$dbname = "web builder";
$link = mysqli_connect($servername, $username, $password, $dbname); 
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
  }
    $sql = "SELECT x, y, height, weight, key , type , text , position FROM suradnice";
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0) { ////////line15///////
        while($row = mysqli_fetch_assoc($result)) {             
        $X=$row["x"] ;
    $Y=$row["y"] ;
    $height=$row["height"] ;
    $weight=$row["weight"];
    $key=$row["key"];
    $type=$row["type"] ;
    $text=$row["text"] ;
    $position=$row["position"]  ;
        }  
    } else {
        echo "error";
    }   
    mysqli_close($link);
}

?>
Run Code Online (Sandbox Code Playgroud)

Abh*_*rty 10

您的查询不应该工作,它的失败.您正在使用保留字key ,这需要包含在`查询中的反引号中:

SELECT x, y, height, weight, `key`, type
Run Code Online (Sandbox Code Playgroud)

MySQL保留字列表