mysql怎么识别事务 mysql查看事物( 九 )


(0.00 sec)
mysql insert into dbtest value(6);
Query OK, 1 row
affected (0.00 sec)
mysql commit;
Query OK, 0 rows affected (0.00
sec)
mysql select * from dbtest;
+------+
| id
|
+------+
|5 |
|6 |
+------+
2 rows in set (0.00
sec)
mysql begin;
Query OK, 0 rows affected (0.00
sec)
mysql insert into dbtest values(7);
Query OK, 1 row affected
(0.00 sec)
mysql rollback;
Query OK, 0 rows affected (0.00
sec)
mysql select * from dbtest;
+------+
| id
|
+------+
|5 |
|6 |
+------+
2 rows in set (0.00
sec)
mysql
*******************************************************************************************************************
[PHP]
function
Tran( $sql ) {
$judge = 1;
mysql_query('begin');
foreach ($sql as $v) {
if
( !mysql_query($v) ) {
$judge =
0;
}
}
if ($judge == 0)
{
mysql_query('rollback');
return
false;
}
elseif ($judge == 1) {
mysql_query('commit');
return true;
}
}
[/PHP]
************************************************
?php
$handler=mysql_connect("localhost","root","");
mysql_select_db("task");
mysql_query("SET
AUTOCOMMIT=0");//设置为不自动提交,因为MYSQL默认立即执行
mysql_query("BEGIN");//开始事务定义
if(!mysql_query("insert
into trans (id)
values('2')"))
{
mysql_query("ROOLBACK");//判断当执行失败时回滚
}
if(!mysql_query("insert
into trans (id)
values('4')"))
{
mysql_query("ROOLBACK");//判断执行失败回滚
}
mysql_query("COMMIT");//执行事务
mysql_close($handler);
?
引自:
mysql怎么识别事务的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于mysql查看事物、mysql怎么识别事务的信息别忘了在本站进行查找喔 。

推荐阅读