創建數據表錯誤: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve
問題描述
<?php // 創建連接 $conn = new mysqli("localhost", "uesename", "password","test"); // 檢測連接 if ($conn->connect_error) {die("連接失敗: " . $conn->connect_error); } // 使用 sql 創建數據表 $sql = "CREATE TABLE new ( id int(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, title varchar(100) NOT NULL, author varchar(20) NOT NULL, content text NOT NULL, created_at datetime NOT NULL, )ENGINE=InnoDB DEFAULT CHARSET=utf8 "; if ($conn->query($sql) === TRUE) { echo "Table MyGuests created successfully"; } else { echo "創建數據表錯誤: " . $conn->error; } $conn->close(); ?>
問題解答
回答1:創建表格的語句,最后這里不能有逗號,去掉應該就可以了。這個是sql語法,前面都需要逗號,最后不需要。
created_at datetime NOT NULL )ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
相關文章:
1. 淺談vue生命周期共有幾個階段?分別是什么?2. macos - mac下docker如何設置代理3. vue添加錨點,實現滾動頁面時錨點添加相應的class操作4. index.php錯誤,求指點5. html - 怎么實現css畫半圓邊框6. javascript - Boolean對象和基本類型Boolean區別7. html5 - 一個用vue組件實現功能的問題8. css3 - 這個右下角折角用css怎么畫出來?9. javascript - 想在編寫weex應用的時候使用rxjs,如何進行相關配置呢?10. javascript - 微信小程序封裝定位問題(封裝異步并可能多次請求)
