当前位置: 代码迷 >> 综合 >> php实现事务 (mysql)
  详细解决方案

php实现事务 (mysql)

热度:90   发布时间:2024-01-21 16:20:03.0
public function runDelTranstraction($sql, $sql2) {mysql_query ( "BEGIN" ); // 开始事务$result = $this->execute_dml ( $sql );$result1 = $this->execute_dml ( $sql2 );if ($result == 1 && $result1 == 1) {mysql_query ( "COMMIT" ); // 提交事务return 1;} else {mysql_query ( "ROLLBACK" ); // 回滚事务return 0;}}

// 执行dml语句public function execute_dml($sql) {$b = mysql_query ( $sql, $this->conn );if (! $b) {return 0;} else {if (mysql_affected_rows ( $this->conn ) > 0) {return 1; // 返回插入那条的id} else {return 2; // 表示没有行受到影响}}}


  相关解决方案