实例
<?php /** * Created by PhpStorm. * 查询数据 */ $pdo = new PDO('mysql:host=localhost;dbname=data','root','root'); $sql = "select name,address,datetime from stu where id > :id"; $stmt = $pdo->prepare($sql); //执行语句 $stmt->execute(['id'=>5]); //一次性取出 //$rows = $stmt->fetchAll(); //foreach ($rows as $row) //{ // echo $row['name'].'-'.$row['address'].'-'.date('Y-m-d',$row['datetime']).'<br>'; //} while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo var_export($row).'<br>'; } $stmt = null; $pdo = null;
运行实例 »
点击 "运行实例" 按钮查看在线实例