Problems related to mysql transaction execution by mysqli

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.