adodb photoshop|用ADODB实现事务

更新时间:2015-01-11    来源:Photoshop    手机版     字体:

【www.bbyears.com--Photoshop】

我想用ADODB实现事务,让两条update语句要么都做要么都不做,但是却始终不成功。代码如下:

$db = NewADOConnection("mysql"); //创建一个ADODB连接对象
$mysql_conn = $db->Connect("localhost","root","", "anna");

$db->BeginTrans();
$ok = $db->Execute("update user set user_name= "098"where id=3");
if($ok)
$ok=$db->Execute("update user set user_name= where id=2");
if ($ok) {$db->CommitTrans();}
else {$db->RollbackTrans(); }
?>

结果却是第一条语句成功了,第二条没有成功。
但是同样我用MYSQL自带的函数却可以实现我要的功能,代码如下:

mysql_query("SET AUTOCOMMIT=0");
$ok1 = $db->Execute("update user set user_name= "098"where id=3");
$ok2=$db->Execute("update user set user_name= where id=2");
if ($ok1 && $ok2 ){ mysql_query("COMMIT");}
else  {mysql_query("ROLLBACK");}
?>

本文来源:http://www.bbyears.com/ps/12135.html

猜你感兴趣

热门标签

更多>>

本类排行