//连接数据库
header("Content-Type:text/html;charset=UTF-8");
$db=new pdo('mysql:host=127.0.0.1;dbname=test','root','root');
//查询一条数据
$sql="select * from `admins` where id=?";//参数绑定
$statement=$db->prepare($sql);//预处理
$data=['1'];
$statement->execute($data);//填入参数并执行
$res=$statement->fetch(PDO::FETCH_ASSOC);
// print_r($res);
//查询多条数据
$sql="select * from `admins` where id>=?";//参数绑定
$statement=$db->prepare($sql);//预处理
$data=['1'];
$statement->execute($data);//填入参数并执行
$res=$statement->fetchAll(PDO::FETCH_ASSOC);
// print_r($res);
// 添加操作
$sql="insert into `admins` (`username`,`nickname`,`email`,`phone`,`password`,`login_status`) values(?,?,?,?,?,?)";//参数绑定
$statement=$db->prepare($sql);//预处理
$data=['xiaojiejie','小姐姐','123456@qq.com','15889650000',md5('123456'),1];
$res=$statement->execute($data);//填入参数并执行
// print_r($res);