abstract:<?php//1.參數(shù)綁定:bindParam() bindValue()//1.創(chuàng)建PDO對象,連接數(shù)據(jù)庫$pdo = new PDO('mysql:host=127.0.0.1;dbname=test','root','root');//2.創(chuàng)建預(yù)處理對象STMT$sql = "SELECT `id`,`name`,`
<?php
//1.參數(shù)綁定:bindParam() bindValue()
//1.創(chuàng)建PDO對象,連接數(shù)據(jù)庫
$pdo = new PDO('mysql:host=127.0.0.1;dbname=test','root','root');
//2.創(chuàng)建預(yù)處理對象STMT
$sql = "SELECT `id`,`name`,`email`,`create_time` FROM `user` WHERE `status`= :status";
$stmt = $pdo->prepare($sql);
//3.執(zhí)行
$stmt->execute([':status'=>1]);
//4.遍歷結(jié)果
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$rows [] =$row;
};
//5.釋放結(jié)果集
$stmt =null;
//6.關(guān)閉連接
$pdo =null;
?>
<style>
table,th,td{
border: 1px solid #333;
}
table{
text-align: center;
border: 1px solid #333;
width: 50%;
margin: 30px auto;
border-collapse: collapse;
}
table caption{
font-size: 1.5cm;
font-weight: bolder;
margin-bottom: 15px;
}
table tr:first-child{
background-color: lightblue;
}
</style>
<table>
<caption>用戶中心</caption>
<tr>
<th>ID</th>
<th>姓名</th>
<th>郵箱</th>
<th>注冊時間</th>
</tr>
<?php foreach ($rows as $row) : ?>
<tr>
<th><?php echo $row['id']?></th>
<th><?php echo $row['name']?></th>
<th><?php echo $row['email']?></th>
<th><?php date_default_timezone_set("PRC"); echo date('Y/m/d',$row['create_time']) ?></th>
</tr>
<?php endforeach; ?>
</table>
Correcting teacher:天蓬老師Correction time:2019-01-16 16:19:43
Teacher's summary:$stmt->execute([':status'=>1]);這里直接用數(shù)組語法就行,不必加冒號的