Blogger Information
Blog 32
fans 0
comment 0
visits 21383
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
面向对象的更新操作和PDO删除操作-2018年5月2日11:49:47
inhylei
Original
685 people have browsed it

面向对象的更新数据

require 'mysqli_connect.php';
$sql = "UPDATE staff SET name=?,salary=? WHERE staff_id=?";

$stmt = $mysqli->stmt_init();
if ($stmt->prepare($sql)){
    $stmt->bind_param('sii', $name, $salary,$staff_id);
    $name='yangguo';$salary=4444;$staff_id=14;
    $stmt->execute();
    if ($stmt->affected_rows){
        echo '更新成功,受影响记录'.$stmt->affected_rows;
    }else{
        echo '更新失败';
    }

}else{
    exit($mysqli->errno . ':' . $mysqli->error);
}
$mysqli->close();

PDO删除数据操作

$pdo = new PDO('mysql:dbname=php', 'root', 'root');
$sql = "DELETE FROM user WHERE user_id=:user_id";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':user_id',4);
$stmt->execute();

总结: 学习的面向对象的更新操作,更进步掌握了面向对象的过程

一定要加深记忆,面向对象的书写步骤

PDO 处理更简单,绑定参数可以使用bindValue或bindParam


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