創(chuàng)建數(shù)據(jù)表錯誤: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve
問題描述
<?php // 創(chuàng)建連接 $conn = new mysqli("localhost", "uesename", "password","test"); // 檢測連接 if ($conn->connect_error) {die("連接失敗: " . $conn->connect_error); } // 使用 sql 創(chuàng)建數(shù)據(jù)表 $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 "創(chuàng)建數(shù)據(jù)表錯誤: " . $conn->error; } $conn->close(); ?>
問題解答
回答1:創(chuàng)建表格的語句,最后這里不能有逗號,去掉應(yīng)該就可以了。這個是sql語法,前面都需要逗號,最后不需要。
created_at datetime NOT NULL )ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
相關(guān)文章:
1. Span標(biāo)簽2. docker-machine添加一個已有的docker主機問題3. redis啟動有問題?4. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””5. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。6. javascript - 計算面積函數(shù)代碼7. javascript - ng-options 設(shè)置默認(rèn)選項,不是設(shè)置第一個哦,看清楚了!8. SessionNotFoundException:會話ID為null。調(diào)用quit()后使用WebDriver嗎?(硒)9. java - Spring MVC無法識別Controller導(dǎo)致返回的結(jié)果是404?10. java - Collections類里的swap函數(shù),源碼為什么要新定義一個final的List型變量l指向傳入的list?
