<?php /* pdo 学习 */ $dsn = ‘mysql:host=localhost;dbname=cswl‘;//构建连接dsn $db = new pdo($dsn,‘root‘,‘‘);//实例化pdo【第二个参数是用户名,第三个为密码】 #.查询 $obj = $db->prepare("show tables;");//准备预处理sql语句 $obj->execute();//执行预处理语句 $obj->fetchALL(PDO::FETCH_ASSOC);//获取结果集 #.插入 $obj = null; $sql = "insert into level_class (sales_id,levelName,gameName,addTime,status) VALUES (?,?,?,?,?)"; $obj = $db->prepare($sql);//准备预处理sql语句 $obj->execute(array(1,‘赤天‘,‘赤天‘,time(),1));//执行一条插入语句 #.删除 $obj = null; $sql = "delete from level_class"; $obj = $db->prepare($sql); $obj->execute(); ?>