abstract:<?php $dsn = 'mysql:host=127.0.0.1;dbname=test'; $pdo = new PDO($dsn,'root','root'); $sql = "SELECT `id`,`name`,`email`,`create
<?php $dsn = 'mysql:host=127.0.0.1;dbname=test'; $pdo = new PDO($dsn,'root','root'); $sql = "SELECT `id`,`name`,`email`,`create_time` FROM `user` WHERE `status`=:status AND `id`>=:id"; $stmt = $pdo->prepare($sql); $status = 0; $stmt->bindParam(':status',$status,PDO::PARAM_INT); $stmt->bindValue(':id',1,PDO::PARAM_INT); $stmt->execute(); $stmt->bindColumn(1,$id,PDO::PARAM_INT); $stmt->bindColumn(2,$name,PDO::PARAM_STR,20); $stmt->bindColumn(3,$email,PDO::PARAM_STR,100); $stmt->bindColumn(4,$time,PDO::PARAM_INT,10); $rows = []; while($stmt->fetch(PDO::FETCH_BOUND)){ echo $id,$name,$email,$time,'<br>'; # 將變量轉(zhuǎn)為關(guān)聯(lián)數(shù)組 $rows[] = compact('id','name','email','time'); } $stmt = null; $pdo = null; ?> <style> table,th,td{border: 1px solid #ccc;} table{text-align: center;border: 1px solid #ccc;width: 50%;margin: 30px auto;border-collapse: collapse;} table caption{font-size: 1.5em;font-weight: bolder;margin-bottom: 15px;} table tr:first-child{background-color: lightsalmon;} </style> <table> <caption>用戶信息表</caption> <tr> <th>ID</th> <th>姓名</th> <th>郵箱</th> <th>注冊(cè)時(shí)間</th> </tr> <?php foreach($rows as $row):?> <tr> <td><?=$row['id']?></td> <td><?=$row['name']?></td> <td><?=$row['email']?></td> <td><?=date("Y-m-d H:i:s",$row['time']);?></td> </tr> <?php endforeach; ?> </table>
Correcting teacher:查無此人Correction time:2019-05-05 09:33:14
Teacher's summary:完成的不錯(cuò)。php最多的就是對(duì)數(shù)據(jù)庫進(jìn)行操作。繼續(xù)加油。