2015-10-24 66 views
-2

我正在研究小型瀏覽器遊戲,但是當我有一個條件連接到MySQLi數據庫所以它不起作用。我找不到我的錯誤。我在PHP和MySQL的情況下犯了什麼錯誤?

其他它應該寫$ name,但它不。

if ($conn->connect_error){ 
    die("Connection failed: ".$conn->connect_error); 
} 

else{ 
    //IF CONNECTION IS GOOD, GET DATA FROM DATABASE 
    $query = "SELECT name, separator, description, maintenance FROM configuration"; 
    $result = mysqli_query($conn, $query); 
    $row = mysqli_fetch_assoc($result); 

    $name = $row['name']; 
    //this ↓↓↓ 
    echo $name; 
} 
+1

'seperator'是一個MySQL的保留字https://dev.mysql.com/doc/refman/5.5/en/keywords.html –

回答

1

使用反引號(``)使用保留字時。

從,

$query = "SELECT name, separator, description, maintenance FROM configuration"; 

要,

$query = "SELECT name, `separator`, description, maintenance FROM configuration"; 
0

嘗試用反引號:

$query = "SELECT name, `separator`, description, maintenance FROM configuration"; 
相關問題