Blogger Information
Blog 41
fans 2
comment 1
visits 26152
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0424作业
郭恒的博客
Original
614 people have browsed it

实例 更新一条数据

<?php
//1.连接数据库
require 'mysqli_connect-1.php';

//2.准备SQL语句
$sql = "UPDATE user SET name=? WHERE id=?;";

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

//4.检测SQL语句
mysqli_stmt_prepare($stmt, $sql);

/* 5参数绑定 */
mysqli_stmt_bind_param($stmt, "si", $name,$id);
$name = '杨康发';
$id = 2;
/* 6执行SQL语句 */
mysqli_stmt_execute($stmt);
echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录';

/* 7注销stmt对象 */
mysqli_stmt_close($stmt);

/* 8关闭数据库连接 */
mysqli_close($db);
?>

运行实例 »

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

实例  删除一条数据

<?php

//1.连接数据库
require 'mysqli_connect-1.php';

//2.准备SQL语句
$sql = "DELETE  FROM `user` WHERE id=?;";

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

//4.检测SQL语句
mysqli_stmt_prepare($stmt, $sql);

/* 5参数绑定 */
mysqli_stmt_bind_param($stmt, "i", $id);
$id = 3;
/* 6执行SQL语句 */
mysqli_stmt_execute($stmt);
echo '<br>更新了'.mysqli_stmt_affected_rows($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
  • 2018-03-16 15:12:44