PDO操作数据库
PDO 预处理
PDOStatement: 预处理对象(SQL语句对象)
prepare(): 预处理方法, 用来生成预处理对象PDOStatement
PDO 绑定参数
bindParam(): 将参数绑定到SQL语句模板上
常用的预定义常量:
- PDO::PARAM_INT: 整数类型
- PDO::PARAM_STR: 字符串类型
- PDO::FETCH_ASSOC: 获取结果集中的关联部分
PDOStatement 类常用方法
- execute(): 执行SQL语句(读/写)
- rowCount(): 返回受影响的记录数量(不适合SELECT)
- errorInfo(): 返回错误信息数组
- fetch(): 获取结果集中的下一行
- fetchAll(): 返回结果集中的所有行
- fetchColumn(): 返回结果集下一行的单独的一列
- bindColumn(): 将结果集某字段绑定到指定变量上
手抄作业
![](https://img.php.cn/upload/image/206/393/561/1574394136144740.jpg)
![](https://img.php.cn/upload/image/966/484/588/1574394144784305.jpg)
![](https://img.php.cn/upload/image/520/972/902/1574394151439439.jpg)
![](https://img.php.cn/upload/image/617/126/190/1574394157299549.jpg)
![](https://img.php.cn/upload/image/931/353/151/1574394163233344.jpg)
![](https://img.php.cn/upload/image/870/232/334/1574394169228520.jpg)