Application MYSQL transaction, combined with PHP database connection

? < PHP
 the require './conn.php' ; 

$ SQL1 = "Update Products SET = Store-Store WHERE ID = 10. 1"; // correct 
$ SQL2 = "Update Products SET = Store Stores WHERE ID = 10 + 2" ; // field error, performs error 

the mysqli_autocommit ( $ Link , to false ); // represents the transaction start 

$ B1 = the mysqli_query ( $ Link , $ SQL1 ); // correct 
$ B2 = the mysqli_query ( $ Link , $ SQL2 ); // error 
// end the current script 

// exit; 
// any one unsuccessful rolled back to its original state
IF (! $ B1 ||! $ B2 ) 
{ 
    echo "failed" ; 
 
    the mysqli_rollback ( $ Link ); // Rollback 
}
 the else 
{ 
    echo "success" ;
     the mysqli_commit ( $ Link ); // submit 
} 
 
mysqli_close ( $ Link ) ;
? < PHP
 $ Host = "localhost" ;
 $ DB_USER = "root"; // database user 
$ db_pass = "root";     // database password 
$ db_name = "the Test";    // Database 
$ TimeZone = "Asia / on Shanghai" ; 

$ Link = mysqli_connect ( $ Host , $ DB_USER , $ db_pass , $ db_name );
 the mysqli_query ( $ Link , "the SET names the UTF8" ); 

header ( "the Content-the Type: text / HTML; charset = UTF-. 8" );
date_default_timezone_set($timezone); // Beijing 
>?

 

Guess you like

Origin www.cnblogs.com/kangshuai/p/12331559.html
Recommended