Correction status:qualified
Teacher's comments:
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]);
点击 "运行实例" 按钮查看在线实例