SQL: INSERT INTO uploader.uploader_users (username, password, email, reg_date)
VALUES ('sa', '40c76244e235aa23e73acb4a457f9748', 'sa@gmail.com', '1132236495'
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near '' at line 2
Errno: 1064
VALUES 子句的左括號 ( 有對應,但右括號 ) 缺失,導致解析器在行尾遇到字串結束仍未閉合,拋出 1064。
-- 錯誤代碼
$db->query("INSERT INTO uploader.uploader_users (username, password, email, reg_date)
VALUES ('$bloginfo[username]', '$bloginfo[password]', '$bloginfo[email]', '$bloginfo[regdate]'");
-- 正確代碼(補上右括號 + 雙引號閉合)
$db->query("INSERT INTO uploader.uploader_users (username, password, email, reg_date)
VALUES ('$bloginfo[username]', '$bloginfo[password]', '$bloginfo[email]', '$bloginfo[regdate]')");
| 錯誤類型 | 典型現象 | 排查技巧 |
|---|---|---|
| 括號不匹配 | 1064 near ')' 或行尾 | IDE 高亮配對、逐行縮排 |
| 引號不閉合/混用 | 1064 near '...'、字串顏色異常 | 統一單雙引號策略、轉義檢查 |
| 保留字未加反引號 | 1064 near 'order', 'group', 'key'... | 所有識別符加 ` |
| 佔位符數量不匹配 | PreparedStatement 參數綁定報錯 | 數 ? 與綁定變數 |
| 中文全形字符 | 1064 不明字符 | 編碼設定 UTF-8、檢查複製貼上 |
SHOW WARNINGS; 查看完整提示。general_log 記錄實際執行的 SQL(僅除錯環境)。echo $sql; exit; 打印最終組裝語句。$stmt = $pdo->prepare("INSERT INTO uploader_users (username, password, email, reg_date) VALUES (?, ?, ?, ?)");
$stmt->execute([$username, $password, $email, $reg_date]);
1064 多為手工拼接 SQL 導致的語法細節錯誤。養成「參數化查詢 + IDE 格式化 + 客戶端驗證」三步驟習慣,可消除 90% 此類問題。