>我正在尝试一次插入我的两个表
但是我一直收到此错误
参数编号无效:绑定变量数与标记数不匹配:
$dbh->beginTransaction();
try{
if(sizeof($return['error'])==0){
$sql = "INSERT INTO circle_call_prefixes (circle, prefix)
VALUES (?,?)";
$q = $dbh->prepare($sql);
$q ->execute(array('123', '123'));
$Last_ID = $dbh->lastInsertId();
$sql_table2 = "INSERT INTO circle_call_destinations
(autoNo,destination, source_circle) VALUES (?,?,?)";
$q = $dbh->prepare($sql);
$q -> execute(array($Last_ID, '123', '123'));
$dbh->commit();
}
可能的问题是什么?谢谢
您尝试在两种情况下$sql运行,但应该在第二种情况下运行 $sql_table2。此代码应该有效:
$dbh->beginTransaction();
try{
if(sizeof($return['error'])==0){
$sql = "INSERT INTO circle_call_prefixes (circle, prefix)
VALUES (?,?)";
$q = $dbh->prepare($sql);
$q ->execute(array('123', '123'));
$Last_ID = $dbh->lastInsertId();
$sql_table2 = "INSERT INTO circle_call_destinations
(autoNo,destination, source_circle) VALUES (?,?,?)";
$q = $dbh->prepare($sql_table2);
$q -> execute(array($Last_ID, '123', '123'));
$dbh->commit();
}