Blogger Information
Blog 14
fans 0
comment 0
visits 8621
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
预处理更新与删除操作2018,04.25 12:16
弗洛加特的博客
Original
414 people have browsed it

实例

<?php

/
 * 预处理更新操作
 */

//1.连接数据库
require 'mysqli_connect.php';
//2,sql语句
$sql = "update ignore staff set salary=? where staff_id = ?;";
//3.创建stmt对象
$stmt = mysqli_stmt_init($db);
//4用stmt对象检测当前sql语句是否正确
if(mysqli_stmt_prepare($stmt,$sql)){
    mysqli_stmt_bind_param($stmt,'ii',$salary,$staff_id);
    $salary = 2800; $staff_id=17;
    if(mysqli_stmt_execute($stmt)){
        if(mysqli_stmt_affected_rows($stmt)){
            echo "更新成功,主键是:".mysqli_stmt_insert_id($stmt);
        }else{
            echo '没有更新数据';
        }
    }else{
        exit(mysqli_stmt_errno($stmt).":".mysqli_stmt_error($stmt));
    }
}else{
    exit(mysqli_stmt_errno($stmt).":".mysqli_stmt_error($stmt));
}
//5注销stmt对象
mysqli_stmt_close($stmt);
//6关闭连接
mysqli_close($db);

运行实例 »

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


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!