php PDO插入不起作用,没有错误

时间:2012-08-23 21:27:57

标签: php pdo

我有这种代码安静,应该将记录插入到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'));

1 个答案:

答案 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