創建數據表錯誤: 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. html5 - java用commons-fileupload上傳文件沒效果!2. javascript - 同步方式寫異步到底指什么?3. 關于docker下的nginx壓力測試4. docker-machine添加一個已有的docker主機問題5. docker鏡像push報錯6. docker安裝后出現Cannot connect to the Docker daemon.7. angular.js - angular內容過長展開收起效果8. nignx - docker內nginx 80端口被占用9. 為什么我ping不通我的docker容器呢???10. dockerfile - 為什么docker容器啟動不了?
