亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

學(xué)完數(shù)據(jù)庫參數(shù)綁定與列綁定技術(shù)的課后小總結(jié)

原創(chuàng) 2018-12-17 19:48:33 229
摘要:學(xué)完了數(shù)據(jù)庫的連接后接連學(xué)習(xí)了數(shù)據(jù)庫的參數(shù)綁定和列綁定技術(shù)后,明白了這項技術(shù)的總要性,以后在框架開發(fā)中會經(jīng)常遇到,雖然還比較含糊需要多練習(xí),以下就是今天的作業(yè)小案例$pdo = new PDO('mysql:host=127.0.0.1;dbname=1_c;','root','root'); $sql="S

學(xué)完了數(shù)據(jù)庫的連接后接連學(xué)習(xí)了數(shù)據(jù)庫的參數(shù)綁定和列綁定技術(shù)后,明白了這項技術(shù)的總要性,以后在框架開發(fā)中會經(jīng)常遇到,雖然還比較含糊需要多練習(xí),以下就是今天的作業(yè)小案例

$pdo = new PDO('mysql:host=127.0.0.1;dbname=1_c;','root','root');

$sql="SELECT`user_id`,`name`,`email`,`create_time` FROM `user` WHERE `status`= :status";
$stmt =$pdo->prepare($sql);


$status = 1;
$stmt->bindParam(':status',$status,PDO::PARAM_INT);
$stmt->execute();

$stmt->bindColumn(1,$user_id,PDO::PARAM_INT);
$stmt->bindColumn(2,$name,PDO::PARAM_STR,20);
$stmt->bindColumn(3,$email,PDO::PARAM_STR,100);
$stmt->bindColumn(4,$createTime,PDO::PARAM_STR,100);

$rows = [];
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
	$rows [] = compact('user_id','name','email','createTime');
}

$stmt = null;
$pdo = null;
?>

<style>
    table,th,td{
   	 border:1px solid #333;
   }

   table{
   	text-align:center;
   	border:1px solid #666;
   	width:50%;
   	margin:30px auto;
   	border-collapse:collapse;
   }
   
   table caption{
   	font-size:1.5en;
   	font-weight:bolder;
   	nargin-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>
     <td><?php echo $row['user_id'] ?></td>
     <td><?php echo $row['name'] ?></td>
     <td><?php echo $row['email'] ?></td>
     <td><?php echo date('Y/m/d',$row['createTime']) ?></td>
     </tr>
 <?php endforeach; ?>

<?php 
foreach ($rows as $row){
	echo'<tr>';
	echo '<td>'.$row['user_id'].'</td>';
	echo '<td>'.$row['name'].'</td>';
	echo '<td>'.$row['email'].'</td>';
	echo '<td>'.$row['createTime'].'</td>';
	echo '<tr>';
}
?>
</table>

1.png

批改老師:天蓬老師批改時間:2018-12-18 09:17:17
老師總結(jié):希望下次看到 你的有點創(chuàng)意的 作業(yè)內(nèi)容

發(fā)佈手記

熱門詞條