Correction status:qualified
Teacher's comments:
<?php //如何正确获取SELECT查询的记录数量 //1.连接数据库 $pdo = new PDO('mysql:host=127.0.0.1;dbname=php;','root','root'); //2.执行操作 $sql = 'SELECT COUNT(*) FROM `staff` WHERE `age`>:age '; $stmt= $pdo->prepare($sql); $stmt->bindValue('age',40,PDO::PARAM_INT); $stmt->execute(); if($stmt->fetchColumn(0)){ $sql = 'SELECT * FROM `staff` WHERE `age`>:age '; $stmt= $pdo->prepare($sql); $stmt->bindValue('age',40,PDO::PARAM_INT); $stmt->execute(); foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $value){ echo '<pre>'; print_r($value); } } //3.关闭数据库连接 $pdo = null ;
点击 "运行实例" 按钮查看在线实例