写出PDO操作数据库的基本步骤
链接数据库,创建pdo对象
$pdo = new PDO($DSN,$username,$password)
执行sql语句
创建sql语句对象 $stmt = $pdo->prepare($sql)
执行sql查询 $stmt ->execute()
对执行结果进行解析或进一步处理
关闭数据库链接 $pdo = null;
2 创始一个学生数据库与学生信息表, 练习常用的增删改查语句
select, update, insert, delete
CREATE TABLE `student` (
`stu_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(50) NOT NULL COMMENT '姓名',
`age` int(10) NOT NULL COMMENT '年龄',
`sex` int(1) NOT NULL COMMENT '性别',
PRIMARY KEY (`stu_id`)
)
select * from student where stu_id = 10;
INSERT INTO `student` (`stu_id`, `name`, `age`, `sex`) VALUES
(1, '超', 30,1);
update student set age = 31 where stu_id= 1;
delete from student where stu_id = 1;