Blogger Information
Blog 33
fans 3
comment 1
visits 23258
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
MySQLi面向对象更新操作+PDO 删除操作演示(4月25日课程)2018/05/14
箭里飘香
Original
607 people have browsed it

MySQLi面向对象实现数据更新操作:

本实例连接数据库脚本引用上节课内容,不在举出,下面是页面代码:

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

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

//3.创建预处理对象STMT
$stmt = $mysqli->stmt_init();

$name = '杨过2';
$birthday = 19880510;

//4.检测STMT->预处理的SQL语句对象
if (!($stmt->prepare($sql))) {

	


	exit($stmt->errno.':'.$stmt->error);
}

//5.执行SQL语句
$stmt->bind_param('is',$birthday,$name);
	
	$stmt->execute();
	if ($stmt->affected_rows > 0) {
		echo "<br>更新成功".$stmt->affected_rows.'条记录';
	} else {
		echo "<br>没有记录被更新";
	}

PDO方式实现数据删除操作

<?php
/**
 * 
 */

//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'=>'8']) ;


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