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 of stored database code
When I tested it, I wrote two insert sentences, the first sentence was correct, the second sentence was wrong, and the execution of the first sentence was always found to be successful.
As if the business is useless, PHP novice, for advice
Only InnoDB and BDB types of data tables in MySQL can support transaction processing
I execute show engines in MySQL, see InnoDB, the result shows that it is support transaction
# Engine, Support, Comment, transactions, XA, savepoints
' InnoDB ', ' DEFAULT ', ' Supports transactions, Row-level locking, and foreign keys ', ' yes ', ' yes ', ' yes '
$result =true;
$resulf =false;
Do you see the problem? The following variable name is incorrectly written
Found, the Sins of sin ~
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. "
";
$result =false;
Break
}
}
if ($result) {
$con->commit ();
}
else{
$con->rollback ();
}
$con->close ();
}
Or the problem, after I changed the code, such as two sql,sql1 correct, sql2 error, using this method to perform, SQL1 data is correctly inserted into the database
But if sql1 wrong, sql2 correct words, two can not insert success, this is actually the role of break, but the role of the business does not reflect AH
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. "
";
$result =false;
Break
}
}
if ($result) {
$con->commit ();
}
else{
$con->rollback ();
}
$con->close ();
}
Or the problem, after I changed the code, such as two sql,sql1 correct, sql2 error, using this method to perform, SQL1 data is correctly inserted into the database
But if sql1 wrong, sql2 correct words, two can not insert success, this is actually the role of break, but the role of the business does not reflect AH
A statement that does not see the start of a transaction.
$con->begin_transaction ();
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. "
";
$result =false;
Break
}
}
if ($result) {
$con->commit ();
}
else{
$con->rollback ();
}
$con->close ();
}
Or the problem, after I changed the code, such as two sql,sql1 correct, sql2 error, using this method to perform, SQL1 data is correctly inserted into the database
But if sql1 wrong, sql2 correct words, two can not insert success, this is actually the role of break, but the role of the business does not reflect AH
A statement that does not see the start of a transaction.
$con->begin_transaction ();
Mysqli inside I did not find begin_transaction () This method ...
http://www.php.net/manual/zh/mysqli.begin-transaction.php
What is this?
I see this.
(PHP 5 >= 5.5.0)
Mysqli::begin_transaction–mysqli_begin_transaction-starts a transaction
is PHP version more than 5.5.0 for transactions?
http://www.php.net/manual/zh/mysqli.begin-transaction.php
What is this?
I call this method inside the code to show the undefined
Look at the engine of the watch, I doubt it's innodb.
Look at the engine of the watch, I doubt it's innodb.
I'm sure the database engine is InnoDB, how does the table look?
Look at the engine of the watch, I doubt it's innodb.
It's the engine of the watch that hasn't changed.