国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PDO預(yù)處理和 參數(shù)綁定

Original 2019-01-16 15:50:36 280
abstract:<?php//1.參數(shù)綁定:bindParam()  bindValue()//1.創(chuàng)建PDO對(duì)象,連接數(shù)據(jù)庫(kù)$pdo = new PDO('mysql:host=127.0.0.1;dbname=test','root','root');//2.創(chuàng)建預(yù)處理對(duì)象STMT$sql = "SELECT `id`,`name`,`

<?php
//1.參數(shù)綁定:bindParam()  bindValue()
//1.創(chuàng)建PDO對(duì)象,連接數(shù)據(jù)庫(kù)
$pdo = new PDO('mysql:host=127.0.0.1;dbname=test','root','root');

//2.創(chuàng)建預(yù)處理對(duì)象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>注冊(cè)時(shí)間</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ù)組語(yǔ)法就行,不必加冒號(hào)的

Release Notes

Popular Entries