<?php
$dsn='mysql:host=localhost;dbname=php';
$user='root';
$pass='root';
//try{
// $pdo=new PDO($dsn,$user,$pass);
// $pdo=null;
// echo '连接成功';
//}
//catch(PDOException $e){
// exit($e->getMessage());
//}
//1.连接数据库
//$pdo=new PDO($dsn,$user,$pass);
////2.创建预处理对象
//$sql="select `id`,`name`,`age` from `staff` where `id`>:id";
////$stmt是PDOStatement类的对象
//$stmt=$pdo->prepare($sql);
////var_dump($stmt);
////4.解析结果集
//if($stmt->execute([':id'=>5])){
// $res=$stmt->fetchAll(PDO::FETCH_ASSOC);
//}else{
// print_r($stmt->errorInfo());
//};
//5.遍历结果集
//print_r($res);
$pdo=new PDO($dsn,$user,$pass);
$stmt=$pdo->prepare("select count('*') as num from `staff`");
$stmt->execute();
$stmt->bindColumn('num',$num);
$stmt->fetch(PDO::FETCH_BOUND);
echo $num.'条记录';