尝试使用PDO打印表格

时间:2019-02-07 19:42:59

标签: php pdo

PDO的新手,我在顶部需要一个PDO连接脚本,但这是我必须尝试的,仅显示由4名雇员及其生日组成的数据库。每当我运行它,我什么都没有。我至少在这里正确的球场吗?

<?php

require "pdoconnect.php";

try{
$stmt = $conn->prepare("SELECT bid, bname, bday FROM birthday"); 
$stmt->execute();
# setting the fetch mode   
$result = $stmt->fetchAll();
if( ! $result){
    print('No Records Found');
} 
else{  
    echo "<table border='1' align='center' cellpadding='5px' cellspacing='2px'>";
    //while($row = $stmt->fetch()) 
    echo "<tr><th>Bid</th><th>Name</th><th>Birthdaay</th><th colspan='2'></th></tr>";
        foreach($result as $row){
            echo "<tr>";
            echo "<td>";
            echo $row['bid'];
            echo "</td>";

            echo "<td>";
            echo $row['bname'];
            echo "</td>";

            echo "<td>";
            echo $row['bday'];
            echo "</td>";
        }
        echo "</table>";
    }
}
catch(PDOException $e){
    echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>

0 个答案:

没有答案