Public & nbsp; static & nbsp; function & nbsp; exec_ SQL _tran ($ arr_ SQL) {$ result = true; $ con & nbsp ;=& nbsp; new & nbsp; MySQLi (DBHOST, DB_USER, D mysqli execution of mysql transactions
public static function exec_sql_tran($arr_sql){
$result=true;
$con = new MySQLi(DBHOST,DB_USER,DB_PASSWD,DB_NAME);
$con->autocommit(FALSE);
foreach($arr_sql as $key=>$sql){
if (!$con->query($sql)) {
echo $con->error."
/";
$resulf=false;
$con->rollback();
break;
}
}
print_r($result);
if($result){
$con->commit();
}
else{
$con->rollback();
}
$con->close();
}
$ Arr_ SQL is an array that stores database code.
I wrote two insert sentences during the test. The first sentence is correct and the second sentence is wrong. at that time, I found that the first sentence was successfully executed.
It seems that the transaction is useless. I'm new to php and want to learn more.
Transactions are shared:
------ Solution --------------------
In MYSQL, only INNODB and BDB data tables support transaction processing.
------ Solution --------------------
$ Result = true;
$ Resulf = false;
Can you see the problem? The following variable name is incorrect.