我正试图一次插入我的两张桌子
但我一直收到此错误
参数号无效:绑定变量数与令牌数不匹配:
$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();
}
可能出现的问题是什么?感谢
答案 0 :(得分:0)
你尝试在两种情况下运行$ 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();
}