php实现mysql事务处理的方法,phpmysql事务处理_PHP教程

WBOY
Release: 2016-07-13 10:10:48
Original
801 people have browsed it

php实现mysql事务处理的方法,phpmysql事务处理

本文实例讲述了php实现mysql事务处理的方法。分享给大家供大家参考。具体分析如下:

要实现本功能的条件是环境 mysql 5.2 /php 5 支持事务的table 类型,需要InnoDB,有了这些条件你就可以做上面的实现了,这个事物回滚操作是大项目经常用到的,像银行,电子商务等都会用到,有需要的朋友可以参考一下.

近期项目软件升级到支持事务处理,做个示例供大家学习参考.

环境 mysql 5.2 /php 5

支持事务的table 类型 需要InnoDB

php mysql 事务处理实现程序代码如下:

复制代码 代码如下:
$LinkID =mysql_connect('localhost:3307','root',*******);
mysql_select_db('web_his',$LinkID);
mysql_query("set names utf8");
 
/* 创建事务 */
mysql_query('START TRANSACTION') or exit(mysql_error());
$ssql1="insert into pf_item values('22','我们','30')";  //执行sql 1
if(!mysql_query($ssql1)){
   echo $ssql1.mysql_errno().":".mysql_error()."
";
   mysql_query('ROLLBACK') or exit(mysql_error());//判断当执行失败时回滚
   exit;
}
$ssql1="insert into pf_item values('21','hell','10')";  //执行sql 2
if(!mysql_query($ssql1)){
  echo $ssql1.mysql_errno().":".mysql_error()."
";
     mysql_query('ROLLBACK') or exit(mysql_error());//判断当执行失败时回滚
   exit;
}
 
mysql_query('COMMIT') or exit(mysql_error());//执行事务
 
mysql_close($LinkID);
?>

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/932486.htmlTechArticlephp实现mysql事务处理的方法,phpmysql事务处理 本文实例讲述了php实现mysql事务处理的方法。分享给大家供大家参考。具体分析如下: 要实现...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!