Blogger Information
Blog 15
fans 0
comment 1
visits 10908
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
pdo 预处理删除----4.25
吴明的博客
Original
738 people have browsed it

pdo 连接数据库是主流的方式,实例化的pdo主要包括四个变量,

$pdo = new PDO ($dsn,$userName,$password);

其中$dsn = "mysql:host;dbname=**;password=**;charset=utf8;port=**";

$sql= "insert table into id = :id";

$pdo->prepare($sql);

$pdo->execute($data);

$pdo = null;

实例

<?php
$dsn = "mysql:host=localhost;dbname=php;charset=utf8;port=3306";
$userName = "root";
$password = "";
try{
 	$pdo = new PDO($dsn,$userName,$password);
}catch(PDOException $e){
	print'connect_error:'.$e->getMessage();
	exit();
}
//准备sql语句
$sql = "DELETE FROM staff WHERE id = :id";
//创建预处理语句对象
$stmt = $pdo ->prepare($sql);
//将参数绑定到预处理语句对象并执行
$stmt ->execute(['id' =>13]);

运行实例 »

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


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