Correction status:Uncorrected
Teacher's comments:
备注:向表格中插入新的行
<?php $dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;'; $dbname = 'root'; $dbpassword = 'root'; $pdo = new PDO($dsn,$dbname,$dbpassword); $sql = 'INSERT INTO `staff` (`name`,`age`,`sex`,`position`,`mobile`,`hiredate`)'; $sql .= ' VALUES (:name, :age, :sex, :position, :mobile, :hiredate)'; $stmt = $pdo->prepare($sql); $k = ['name','age','sex','position','mobile','hiredate']; $v = ['沐泓',13,'男','丐帮帮主','13333333333',time()]; $d = array_combine($k,$v); $stmt->execute($d); echo $stmt->rowCount();
点击 "运行实例" 按钮查看在线实例
备注:删除表中的行
<?php $dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;'; $dbname = 'root'; $dbpassword = 'root'; $pdo = new PDO($dsn,$dbname,$dbpassword); $sql = 'DELETE FROM `staff` WHERE `name`=:name'; $stmt = $pdo->prepare($sql); $stmt->execute(['name'=>'沐泓']); echo $stmt->rowCount();
点击 "运行实例" 按钮查看在线实例
备注:修改表中的数据
<?php $dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;'; $dbname = 'root'; $dbpassword = 'root'; $pdo = new PDO($dsn,$dbname,$dbpassword); $sql = 'UPDATE `staff` SET `position` = :position WHERE `id`=:id'; $stmt = $pdo->prepare($sql); $stmt->execute(['position'=>'前台', 'id'=>5]); echo $stmt->rowCount();
点击 "运行实例" 按钮查看在线实例