Blogger Information
Blog 29
fans 0
comment 0
visits 29221
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PDO预处理删除操作
咸鱼梦
Original
821 people have browsed it
<?php
header('Content-Type:text/html;charset=UTF-8');
*try {
	$dsn = 'mysql:dbname=demo';
	$userNmae = 'root';
	$password = 'root';
	$pdo = new PDO($dsn,$userNmae,$password);
	
	//
	$sql = "DELETE FROM `user` WHERE `id`=:id";
	//执行预处理sql删除语句,创建一个PDOStatement对象
	$pdoStmt = $pdo->prepare($sql);
	if ($pdoStmt == true) {
		//声明要删除的id
		$data = ['id'=>4];
		//绑定要删除的id
		$pdoStmt->bindParam(':id',$data['id']);
		$res = $pdoStmt->execute($data);
		if ($res == true) {
			echo '删除成功!';
		} else {
			echo '删除失败!!!';
		}
	} else {
		print_r($pdo->errorInfo());
	}
	
} catch (PDOException $e) {
	print 'Connect ERROR'.$e->getMessage();
	dre();
}

简写:

<?php
header('Content-Type:text/html;charset=UTF-8');
//连接数据库
$pdo = new PDO('mysql:dbname=demo','root','root');
//执行sql删除语句
$pdoStmt = $pdo->prepare("DELETE FROM `user` WHERE `id`=:id");
//执行pdo对象并判断结果
echo $pdoStmt->execute(['id'=>13]) ? '删除成功!' : '删除失败!!!';


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