In this paper, the MySQL transaction problem of PHP is analyzed. Share to everyone for your reference, as follows:
For MyISAM databases, you can control the conduct of transactions:
- $MYSQLRL = mysql_connect ($db _config ["host"], $db _config ["User"], $db _config ["Pass"], true);
- if (! $mysqlrl) {
- $msg = Mysql_error ();
- Die (' Could not connect: '. $msg);
- }
- mysql_select_db ($db _config ["Data"], $MYSQLRL) or Die ("Error: Database Exception");
- mysql_query ("SET NAMES ' UTF8 '");
- Date_default_timezone_set (' Asia/shanghai ');
- /**
- * Transaction operation Process BEGIN COMMIT END
- */
- mysql_query (' BEGIN ');
- $flag 3 = mysql_query ($sql 3);
- $flag 1 = mysql_query ($sql 1);
- $flag 2 = mysql_query ($sql 2);
- if ($flag 1 && $flag 1 && $flag 3) {
- mysql_query (' COMMIT ');
- mysql_query (' END ');
- $data. = "\ r \ n". "Update record Success";
- Write_file ($file, $data);
- return true;
- } else {
- Print mysql_error ();
- mysql_query (' ROLLBACK ');
- mysql_query (' END ');
- $data. = "\ r \ n". "Update record failed (⊙o⊙)!!!" ";
- Write_file ($file, $data);
- return false;
- }
- }
Example analysis of PHP MySQL transaction problem