Blogger Information
Blog 48
fans 0
comment 0
visits 36371
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
pdo查询数据-2018.08.30
雨天的博客
Original
559 people have browsed it

实例

<?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;

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!