我的连接文件如下所示
static public function connect(){
$link = new PDO("mysql:host=localhost;dbname=xx", "xx", "xx");
$link->setAttribute(pdo::ATTR_AUTOCOMMIT, 0);
$link -> exec("set names utf8");
return $link;
}
} }
“我的带有嵌套数据库的代码插入和更新”是以下代码
$inv_no=1047;
$chick_id = 1;
$chick_price = 15;
$chick_qty = 1000;
$sup_id=3;
$sub_total=$chick_price*$chick_qty;
$current= new ProcsModel();
$inv_info=$current->Mdl_Invtotal_Itemcount($inv_no);
$sup_info=$current->Mdl_Sup_Total($sup_id);
$sup_cur_balance=$sup_info['balance'];
$sup_new_balance=$sup_cur_balance+$sub_total;
$current_inv_total=$inv_info['inv_total'];
$current_item_count=$inv_info['item_count'];
$new_count=$current_item_count+1;
$new_inv_total=$current_inv_total+$sub_total;
$stmt = Connection::connect()->beginTransaction();
// Add Item
$stmt = Connection::connect()->prepare("INSERT INTO `pro_items` (inv_no, chick_id, chick_price, chick_qty, sub_total) VALUES ($inv_no, $chick_id, $chick_price, $chick_qty, $sub_total )");
if ($stmt->execute()) {
//Update Invoice Table
$stmt = Connection::connect()->prepare("UPDATE pro_inv set inv_total = $new_inv_total, item_count = $new_count WHERE inv_no = $inv_no");
if ($stmt->execute()) {
//Update Suppliers Table
$stmt = Connection::connect()->prepare("UPDATE suppliers set balance = $sup_new_balance WHERE sup_id = $sup_id");
if ($stmt->execute()) {
$stmt = Connection::connect()->commit();
$chick_type=ProcsModel::Mdl_Get_chick_type($chick_id);
$item= array ('item_count'=>$new_count,
'chick_type'=>$chick_type,
'chick_price'=>$chick_price,
'sub_total'=>$$sub_total,
'inv_total'=>$new_inv_total,
'chick_qty'=>$chick_qty);
var_dump ($item);
}
else{
$stmt = Connection::connect()->rollBack();
return 'error';
exit();
}
}
else{
$stmt = Connection::connect()->rollBack();
return 'error';
exit();
}
}
else {
$stmt = Connection::connect()->rollBack();
return 'error';
exit();
}
$stmt -> close();
$stmt = null;
运行此命令时,出现错误Uncaught PDOException:我提交事务第55行的行中没有活动事务
任何人都可以帮助我弄清楚为什么我会收到此错误