我有这种代码安静,应该将记录插入到mysql数据库中:
$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) VALUES (?, ?, ?, ?, ?, ?, ?)')";
$stmt = $pdo->prepare($sql);
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($pdo->errorInfo());
}
$stmt->execute(array('wer','wer','wer','2','wer','wer','wer'));
我没有收到任何错误,并且记录未显示在表格中。可能出现什么问题?
更新
由于以下答案,这是完整的工作代码:
$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($pdo->errorInfo());
}
$stmt->execute(array('wer','wer','wer','2','wer','wer','wer'));
答案 0 :(得分:5)
SQL命令末尾有语法错误。删除额外的')
。它应该是:
$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7)
VALUES (?, ?, ?, ?, ?, ?, ?)";
而不是
$sql = "INSERT INTO connections (column1, column2, column3, column4, column5, column6, column7)
VALUES (?, ?, ?, ?, ?, ?, ?)')";
^^--- error here