MySQLi 预处理批量删除语句

来源:互联网 发布:瓷砖进销存软件 编辑:程序博客网 时间:2024/05/19 03:24
<?phpinclude("config.php");if(empty($_SESSION['username'])){header("Location: index.php");    exit;}//$all_id=$_POST['all_id'];$all_id='540,541';if($all_id!=""){    $sql = "DELETE FROM data_type WHERE id=?";//mysqli_query($con,"DELETE FROM Persons WHERE LastName='Griffin'");     // 为 mysqli_stmt_prepare() 初始化 statement 对象    $stmt = mysqli_stmt_init($conn);     //预处理语句    if (mysqli_stmt_prepare($stmt, $sql)) {        // 绑定参数        mysqli_stmt_bind_param($stmt, 'i', $id);         //循环删除 设置参数并执行$all_id = explode(',',$all_id);  for($i=0;$i<count($all_id);$i++){  $id = $all_id[$i];mysqli_stmt_execute($stmt);}              }$info=1;}else{$info=0;}if($info==1){$msg='成功'.$_POST['all_id'].'!';echo $msg;}else{$msg='失败'.$_POST['all_id'].'!';echo $msg;}?>

0 0
原创粉丝点击