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

完成參數(shù)綁定技術(shù)案例,創(chuàng)建自定義模板,格式化輸出數(shù)據(jù)表中的數(shù)據(jù)

??? 2019-04-13 23:23:25 257
????:<?php //    數(shù)據(jù)庫(kù)連接信息     $type = 'mysql';     $host = '127.0.0.1';     $dbName&nbs
<?php
//    數(shù)據(jù)庫(kù)連接信息
    $type = 'mysql';
    $host = '127.0.0.1';
    $dbName = 'php_io';
    $charset = 'utf8';
    $user = 'root';
    $password = 'root';
    $dsn = $type.':host='.$host.';dbname='.$dbName.';charset='.$charset;
    $pdo = new PDO($dsn,$user,$password);
//預(yù)定義語(yǔ)句
    $sql = "SELECT `id`,`name`,`sex`,`age`, `email`,`create_time` FROM `user` WHERE `age`>:age LIMIT :num";
    $stmt = $pdo->prepare($sql);
    //設(shè)置顯示記錄條數(shù)
    $num = 6;
    //篩選條件
    $age = 65;
    //參數(shù)綁定
    $stmt ->bindParam(':num',$num,$pdo::PARAM_INT);
    $stmt ->bindValue(':age',$age,$pdo::PARAM_INT);

    //執(zhí)行預(yù)定義語(yǔ)句
    $stmt->execute();
    //解析遍歷
    $res  = $stmt->fetchAll($pdo::FETCH_ASSOC);
//    關(guān)閉連接
    $stmt = null;
    $pdo = null;
?>
<!----------------------------表格樣式------------------------------------------------->
<style>
    .table{
        margin:50px auto;
        width: 80%;

    }
   .table,th,td{
       border: 1px solid #ccc;
       border-collapse: collapse;
       text-align: center;

   }
    .table caption{
       font-size: 1.5em;
        font-weight: bold;
        background-color: lightblue;
    }
</style>

<!----------------------------------------------表格模板--------------------------------------------->
<table class="table">
    <caption>梁山英雄榜</caption>
    <tr>
        <th>工號(hào)</th>
        <th>姓名</th>
        <th>性別</th>
        <th>年齡</th>
        <th>郵箱</th>
        <th>上山時(shí)間</th>
    </tr>
    <?php foreach ($res as $row):?>
        <tr>
            <td><?php echo $row['id']?>     </td>
            <td><?php echo $row['name']?></td>
            <td><?php echo $row['sex']?'男':'女'; ?></td>
            <td><?php echo $row['age']?></td>
            <td><?php echo $row['email']?></td>
            <td><?php echo date('Y-m-d',$row['create_time'])?></td>
        </tr>
    <?php endforeach;?>
</table>

20190413231816.jpg

經(jīng)過(guò)本章節(jié)的學(xué)習(xí)練習(xí)對(duì)PDO操作數(shù)據(jù)庫(kù)技術(shù)基本掌握。數(shù)據(jù)庫(kù)技術(shù)過(guò)多強(qiáng)大,后續(xù)更加深入學(xué)習(xí)才能掌握得更加得心應(yīng)手

?? ???:天蓬老師?? ??:2019-04-14 21:52:25
???? ??:數(shù)據(jù)表的操作, 也前端密不可分的, 其實(shí)你的這個(gè)作業(yè), 已經(jīng)有點(diǎn)MVC的特點(diǎn)了

??? ??

?? ??