Blogger Information
Blog 35
fans 2
comment 0
visits 22579
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
面向过程--mysqli预处理更新和删除
小学僧的博客
Original
658 people have browsed it

1.预处理更新

实例

<?php
require 'mysqli_con.php';

$sql = "UPDATE  staff SET salary=10000 WHERE age=?;";

$stmt = mysqli_stmt_init($db);		//创建对象

if(mysqli_stmt_prepare($stmt,$sql)){			//检测语句
	mysqli_stmt_bind_param($stmt,"i",$age);		//绑定参数
	$age = 43;
	mysqli_stmt_execute($stmt);		//执行语句
	echo 'new update:'.mysqli_stmt_affected_rows($stmt);
	
	
} else {
    exit(mysqli_stmt_errno($stmt).':'.mysqli_stmt_error($stmt));
}

mysqli_stmt_close($stmt);

mysqli_close($db);

运行实例 »

点击 "运行实例" 按钮查看在线实例

2.预处理删除

实例

<?php
require 'mysqli_con.php';

$sql = "DELETE FROM staff WHERE staff_id=?";

$stmt = mysqli_stmt_init($db);		//创建对象

if(mysqli_stmt_prepare($stmt,$sql)){			//检测语句
	mysqli_stmt_bind_param($stmt,"i",$staff_id);		//绑定参数
	$staff_id = 7;
	mysqli_stmt_execute($stmt);		//执行语句
	echo 'new delete:'.mysqli_stmt_affected_rows($stmt);
	
	
} else {
    exit(mysqli_stmt_errno($stmt).':'.mysqli_stmt_error($stmt));
}

mysqli_stmt_close($stmt);

mysqli_close($db);

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post