pdo为什么不用用户名和密码可以操作成功 $dsn="mysql:host=localhost;dbname=test"; try{ $pdo=newPDO($dsn); echo"连接成功"; }catch(PDOException$e){ echo"连接失败".$e-getMessage(); } try{ $pdo-beginTransaction(); $goodprice=5; $id_out=15; $id_in=
pdo为什么不用用户名和密码可以操作成功
<br /> $dsn = "mysql:host=localhost;dbname=test"; <br /> <br /> try{<br /> $pdo = new PDO($dsn);<br /> echo "连接成功";<br /> }catch(PDOException $e){<br /> echo "连接失败".$e->getMessage();<br /> }<br /> <br /> <br /> try{<br /> $pdo->beginTransaction();<br /> $goodprice = 5;<br /> $id_out = 15;<br /> $id_in =16;<br /> $sql1 ="update price set goodprice【本文来自鸿网互联 (http://www.68idc.cn)】 = goodprice -{$goodprice} where id ={$id_out}";<br /> $sql2 ="update price set goodprice = goodprice +{$goodprice} where id ={$id_in}"; <br /> if(!$affectd_rows =$pdo->exec($sql1)){<br /> throw new PDOException("{$id_out}转出失败");<br /> }<br /> if(!$affectd_rows =$pdo->exec($sql2)){<br /> throw new PDOException("{$id_in}转入失败");<br /> }<br /> $pdo->commit();<br /> echo "提交成功";<br /> }catch(PDOException $e){<br /> echo $e->getMessage();<br /> $pdo->rollback();<br /> } <br />