Blogger Information
Blog 45
fans 2
comment 1
visits 26363
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2018年4月25号15:30分
哈的博客
Original
566 people have browsed it

总结:

基本不步骤如下:

1连接数据库

2准备多条查询sql语句

3创建stmt对象

4执行查询并检测

4—1绑定参数

4—2执行sql语句

实例

<?php
//连接数据库
require 'mysqli_connect.php';
//准备多条查询sql语句
// $sql = 'UPDATE staff SET salary=? WHERE staff id=?;';
$sql = 'DELETE FROM staff WHERE staff id=?;';
//创建stmt对象
$stmt = mysqli_stmt_init($db);
//执行查询并检测
if (musqli_stmt_prepae($stmt,$sql)) {
	//绑定参数
	mysqli_stmt_bind_param($stmt,$id);
	$id = 3;
	//执行sql语句
	mysqli_stmt_execute($stmt);
	echo '<br>删除'mysqli_stmt_affected_rows($stmt).'条记录,主键是:'.mysqli_stmt_insert_id($stmt);


} else {
	exit (mysqli_stmt_errno($stmt).':'.misqli_stmt_error($stmt));
}
//注销对象stmt
mysqli_stmt_close($stmt);
//关闭数据库连接
mysqli_close($db);


<?php
//连接数据库
require 'mysqli_connect.php';
//准备多条查询sql语句
$sql = 'UPDATE staff SET salary=? WHERE staff id=?;';
// $sql = 'DELETE FROM staff WHERE staff id=?;';
//创建stmt对象
$stmt = mysqli_stmt_init($db);
//执行查询并检测
if (musqli_stmt_prepae($stmt,$sql)) {
	//绑定参数
	mysqli_stmt_bind_param($stmt,$salary,$id);
	$id = 7;
	$salary = 200;
	//执行sql语句
	mysqli_stmt_execute($stmt);
	echo '<br>更新了'mysqli_stmt_affected_rows($stmt).'条记录,主键是:'.mysqli_stmt_insert_id($stmt);


} else {
	exit (mysqli_stmt_errno($stmt).':'.misqli_stmt_error($stmt));
}
//注销对象stmt
mysqli_stmt_close($stmt);
//关闭数据库连接
mysqli_close($db);

运行实例 »

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

5注销对象stmt

6关闭数据库连接



Correction status:Uncorrected

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