php同时删除两张表 用MySQL事务处理机制
php同时删除两张表 用MySQL事务处理机制
mysql_query("START TRANSACTION");
执行删除第一表
执行删除第二张表
两张表都执行成功
mysql_query("COMMIT");
否则回滚
mysql_query("ROLLBACK");
代码片段:
$id = $_GET['id']; $sql1 = "delete from by_msg where 1id='{$id}'"; //删除留言表sql $sql2 = "delete from by_replymsg where msgid='{$id}'";//删除回复表sql $conn = mysql_conn(); mysqli_query($conn,"START TRANSACTION"); $query1 = mysqli_query($conn,$sql1); $query2 = mysqli_query($conn,$sql2); if($query1&&$query2) { mysqli_query($conn,"COMMIT"); echo "<script> alert('删除留言成功');location.href='message.php';</script>"; exit; } else { mysqli_query(conn,"ROLLBACK"); echo "<script> alert('删除留言失败');location.href='message.php';</script>"; exit; }
上一篇:jQuery样式操作CSS