Blogger Information
Blog 46
fans 1
comment 1
visits 30224
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MySQLi面向过程:使用预处理技术实现更新与删除操作-2018年4月24日
笨鸟先飞
Original
541 people have browsed it

使用预处理技术实现更新操作:


实例

<?php
/**
 * 预处理更新操作
 */
//1.连接数据库
require 'mysqli_connect.php';

//2.准备sql语句
$sql = "UPDATE phone SET phone_id=? WHERE name=?; ";
//3.创建stmt对象,将sql语句转为stmt对象
$stmt = mysqli_stmt_init($db);
//4.用stmt对象检测sql语句是否正确
mysqli_stmt_prepare($stmt,$sql);
//5.绑定参数
mysqli_stmt_bind_param($stmt,'is',$phone_id,$name);
$phone_id=7;$name='覃';
//6.执行sql
mysqli_stmt_execute($stmt);
//7.注销stmt对象
mysqli_stmt_close($stmt);
//8.关闭数据库
mysqli_close($db);

运行实例 »

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


使用预处理技术实现删除操作:


实例

<?php
/**
 * 预处理删除操作
 */
//1.连接数据库
require 'mysqli_connect.php';

//2.准备sql语句
$sql = "DELETE FROM phone WHERE name=?;";

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

//4.用stmt对象检测预处理是否正确
mysqli_stmt_prepare($stmt,$sql);

//5.绑定参数
mysqli_stmt_bind_param($stmt,'s',$name);
$name='哈哈';
//6.执行
mysqli_stmt_execute($stmt);
//7.注销stmt对象
mysqli_stmt_close($stmt);
//8.关闭数据库
mysqli_close($db);

运行实例 »

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


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