創建數據表錯誤: 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 ";
相關文章:
