Blogger Information
Blog 34
fans 2
comment 2
visits 22731
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MySQLi面向对象实现更新操作及 PDO实现删除操作 20180426-14:51
AsNwds_MIS王的博客
Original
596 people have browsed it

实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/26
 * Time: 13:29
 */
//1、连接数据库
require 'mysqli_config.php';
//2、执行查询

$sql = "update user set user_name = ? where user_id = 1  ";
//3、 初始化stmt
$stmt = $mysqli->stmt_init();

if ($stmt->prepare($sql)){
    $stmt->bind_param('s',$user_name); //绑定参数
    $user_name = '小王1';
    $stmt->execute();
    if ($stmt->affected_rows>0){
        echo '<br>更新了'.$stmt->affected_rows.'条记录';
    } else
    {
        echo '<br>无更新记录';
    }
}else {
    echo $stmt->error;
}
//关闭数据库
$mysqli->close();

运行实例 »

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


实例

<?php
/医院
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/26
 * Time: 14:58
 */
//1.连接数据库,创建pdo对象
$pdo = new PDO('mysql:dbname=php','root','root');
//2、创建对象
$stmt = $pdo->prepare("delete from user where user_id=:user_id");

//3、绑定参数
$stmt -> execute(['user_id'=>1]);

echo '成功更新了'.$stmt->rowCount().'条记录';

运行实例 »

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



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