iT邦幫忙

0

SQL 預期之外的字元

sql

https://ithelp.ithome.com.tw/upload/images/20190425/20109091YBNACiIWFP.pngINSERT INTO tb_student(id, classid, username, connector, fstriplength, cable, length, fglands, nylonlength, bglands, nylonlname, ctime, cablename, bstriplength, bconnector, remarks) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12],[value-13],[value-14],[value-15],[value-16])

請問為何會出現這訊息呢?
SQL 預期之外的字元
https://ithelp.ithome.com.tw/upload/images/20190425/20109091a7NpTLGGxp.png

石頭 iT邦高手 1 級 ‧ 2019-04-25 06:56:32 檢舉
[value-1] ...... 你想要新增哪種的資料?
b3321597 iT邦新手 5 級 ‧ 2019-04-25 07:37:20 檢舉
--
-- 表的结构 `tb_student`
--

DROP TABLE IF EXISTS `tb_student`;
CREATE TABLE IF NOT EXISTS `tb_student` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`classid` int(10) DEFAULT NULL COMMENT '班级表id',
`username` varchar(30) DEFAULT NULL COMMENT '学生名',
`code` varchar(30) DEFAULT NULL COMMENT '学号',
`sex` varchar(10) DEFAULT '1' COMMENT '1男2女',
`age` varchar(100) DEFAULT NULL COMMENT '年龄',
`phone` varchar(20) DEFAULT NULL COMMENT '联系电话',
`heights` varchar(10) DEFAULT NULL,
`weights` varchar(10) DEFAULT NULL,
`expertise` varchar(100) DEFAULT '无' COMMENT '专长',
`remarks` varchar(255) DEFAULT '无' COMMENT '备注',
`ctime` int(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
b3321597 iT邦新手 5 級 ‧ 2019-04-25 07:38:08 檢舉
這是他原本建立的 我只是把像 CODE SEX AGE之類的全部重新命名並增加這樣@@
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
小魚
iT邦大師 1 級 ‧ 2019-04-25 08:10:22

你的編碼很亂,
到底是要 utf8_general_ci,
還是要 utf8mb4_general_ci?
最好是要統一比較好.

前者主要針對全繁體中文,
後者是針對各種語言,
尤其是有簡體又有繁體用這種會比較好,
最好從資料庫到資料表都用同樣的語系,
然後從後端抓資料的時候如果會出現亂碼,
可能語系也要處理,
MySql的連線字串要加入 charset=utf8mb4
(或 charset=utf8, 不過現在預設似乎就是utf8)

b3321597 iT邦新手 5 級 ‧ 2019-04-25 09:34:23 檢舉

阿阿阿這部份我沒改到哈哈

淺水員 iT邦大師 6 級 ‧ 2019-04-25 10:45:06 檢舉

好像有一些罕見中文字要用 utf8mb4
差別主要是最多允許用幾個byte儲存一個字

我現在也是用 utf8mb4
不過其實用utf8mb4跟utf8差別性不大。
只是某些特殊字元utf8mb4能直接支援處理。
用utf8的話,碰到特殊的字元會變轉碼。

0

我其實很想知道,你的[]用法是從何而來的?
你那段sql語法就是在告訴你無法判斷的[]用法。

你會不會把mssql跟mysql給搞混了

b3321597 iT邦新手 5 級 ‧ 2019-04-25 09:35:48 檢舉

那sql語法是自動帶入的@@
我按insert之後就代入這串

那只是標記。你得自行去更換資料。
sql的語法並沒有[]的用法。但有取代式的做法。
你拿到的是範例的語法。要自行更換。

0
純真的人
iT邦大師 1 級 ‧ 2019-04-25 09:24:47

新奇..
[value-1] ← 這個應該是phpmyadmin產生的吧~
你要自己填資料吧?

INSERT INTO tb_student(id, classid, username, connector, fstriplength, cable, length, fglands, nylonlength, bglands, nylonlname, ctime, cablename, bstriplength, bconnector, remarks) VALUES ('資料1','資料2','資料3','資料4','資料5','資料6','資料7','資料8','資料9','資料10','資料11','資料12','資料13','資料14','資料15','資料16');
b3321597 iT邦新手 5 級 ‧ 2019-04-25 09:39:24 檢舉

storm.rar
http://gofile.me/4n65l/yVORJntPz
這是我的源檔

就是要你自己手動建立資料吧..

b3321597 iT邦新手 5 級 ‧ 2019-04-28 22:11:18 檢舉

我想請問INSERT INTO這行的順序跟bindParam那排的有對應關係嗎?
因為我增加一行後 再RUN就變空白的了><

//增加学生信息
public function addStudent($studentInfo){
try{
$sql = "INSERT INTO tb_student(classid,username,code,sex,age,phone,heights,weights,expertise,ctime,remarks) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
$queryobj = $this->db->prepare($sql);
$queryobj -> bindParam(1,$studentInfo -> classid,PDO::PARAM_INT);
$queryobj -> bindParam(2,$studentInfo -> username,PDO::PARAM_STR);
$queryobj -> bindParam(3,$studentInfo -> code,PDO::PARAM_STR);
$queryobj -> bindParam(4,$studentInfo -> sex,PDO::PARAM_STR);
$queryobj -> bindParam(5,$studentInfo -> age,PDO::PARAM_STR);
$queryobj -> bindParam(6,$studentInfo -> phone,PDO::PARAM_STR);
$queryobj -> bindParam(7,$studentInfo -> heights,PDO::PARAM_STR);
$queryobj -> bindParam(8,$studentInfo -> weights,PDO::PARAM_STR);
$queryobj -> bindParam(9,$studentInfo -> expertise,PDO::PARAM_STR);
$queryobj -> bindParam(10,$studentInfo -> ctime,PDO::PARAM_INT);
$queryobj -> bindParam(11,$studentInfo -> remarks,PDO::PARAM_STR);
$queryobj -> execute();
$result = $queryobj ->rowCount();
if($result !== false){
return true;
}else{
return false;
}
}catch(PDOException $e){
die($e -> getMessage());
}
}

我要發表回答

立即登入回答