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; // 表示没有行受到影响}}}