Blogger Information
Blog 34
fans 2
comment 2
visits 22864
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Mysqli 预处理-更新、删除操作 20180425-11:43
AsNwds_MIS王的博客
Original
674 people have browsed it

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/25
 * Time: 10:17
 */
//1、连接数据库
require 'mysqli_config.php';
//2、执行查询
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);

$sql = "update user set user_name = ? where user_id = 1  ";
$user_name = '王老师4';
//创建对象
$stmt = mysqli_stmt_init($con);

if (mysqli_stmt_prepare($stmt,$sql)){
    //参数绑定
    mysqli_stmt_bind_param($stmt,"s",$user_name);
    //执行语句
    mysqli_stmt_execute($stmt);
    echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录'.mysqli_stmt_insert_id($stmt);
}
//注销对象
mysqli_stmt_close($stmt);
//关闭数据库
mysqli_close($con);

运行实例 »

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

删除:

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/25
 * Time: 11:46
 */
require 'mysqli_config.php';
//2、执行查询
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);

$sql = "delete from user where user_id=?   ";

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

if (mysqli_stmt_prepare($stmt,$sql)){
    //执行语句
    $user_id = 1;
    mysqli_stmt_execute($stmt);
    echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录';
}
//注销对象
mysqli_stmt_close($stmt);
//关闭数据库
mysqli_close($con);

运行实例 »

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


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