2013-11-23 129 views
0

我試圖創建一個列名爲「Change」的表。下面是我用列名爲change的奇怪MySQL行爲

$create=mysql_query("CREATE TABLE table_name (ID int NOT NULL AUTO_INCREMENT KEY, 
Name TEXT ,Property TEXT ,Change TEXT ,Change_Percent TEXT ,Low_Look TEXT , 
High_Look TEXT ,Low_Proximity TEXT ,Time_Index TEXT ,carom TEXT ,qualification 
TEXT)"); 

// Execute query 
if (mysql_query($con,$create)) 
    { 
    echo "Table created successfully"; 
    } 
else 
    { 
    echo "Error creating table: " . mysql_error($conn); 
    } 

此代碼,然後給了我下面的錯誤

Warning: mysql_query() expects parameter 2 to be resource, boolean given in 
C:\xampp\htdocs\stock\test.php on line 20 
Error creating table: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 
'Change TEXT ,Change_Percent TEXT ,Low_Look TEXT ,High_Look TEXT ,Low_Proximity TEXT ' 
at line 1 

嘗試一些東西,我注意到,服用更改從「E」的解決了這個問題之後。現在有什麼可能導致它,並有沒有辦法命名一列「更改」?如果這是絕對必要的。

+1

見列表:MySQL中保留關鍵字] **(http://dev.mysql.com/doc/refman/5.6/en /reserved-words.html)** –

+0

你可以在改變時使用反引號,但不鼓勵使用保留字 –

+0

感謝鏈接@ypercube很好的書籤它的時間.. – TDsouza

回答

1

更改是一個保留字。你可以嘗試換一個名字,或者至少用反引號包裝它。

1

change是MySQL的關鍵字,使用反引號(') 「變」