Home > Backend Development > PHP Tutorial > PHP mysql事务问题实例分析_PHP

PHP mysql事务问题实例分析_PHP

WBOY
Release: 2016-05-28 11:49:15
Original
960 people have browsed it

本文实例分析了PHP的mysql事务问题。分享给大家供大家参考,具体如下:

对于myisam数据库,可以控制事务的进行:

$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: 数据库异常" );
mysql_query ( "SET NAMES 'utf8'" );
date_default_timezone_set ( 'Asia/Shanghai' );
/**
* 事务操作过程 BEGIN COMMIT END
*/
mysql_query ( 'BEGIN' );
$flag3 = mysql_query ( $sql3);
$flag1 = mysql_query ( $sql1);
$flag2 = mysql_query ( $sql2);  
    if ($flag1 && $flag1 && $flag3) {
    mysql_query ( 'COMMIT' );
    mysql_query ( 'END' );
    $data .= "\r\n" . "更新记录成功";
    write_file ( $file, $data );
    return true;
  } else {
    print mysql_error ();
    mysql_query ( 'ROLLBACK' );
    mysql_query ( 'END' );
    $data .= "\r\n" . "更新记录失败(⊙o⊙)!!!";
    write_file ( $file, $data );
    return false;
  }
}

Copy after login

更多关于PHP操作MySQL相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template