<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$dbms = 'mysql';
$dbName = 'angelo_one';
$user = 'root';
$pwd = '****';
$host = 'localhost';
$query = "select * from Persons";
$dsn = "$dbms:host=$host; dbname=$dbName";
try{
$pdo = new PDO($dsn, $user, $pwd);
echo '数据库链接成功!';
$result = $pdo->prepare($query);
$result -> execute();
}
catch(Exception $e){
echo $e -> getMessage() . "<br>";
}
//mysql_connect("localhost", "root", "admin");
//mysql_select_db("angelo_one");
//$result = mysql_query("select * from Persons");
echo '<table border="1">';
echo '<tr>';
echo '<th>FirstName</th><th>LastName</th><th>Age</th></tr>';
while ($row = $result -> fetch(PDO::FETCH_ASSOC)){
echo "<tr>";
echo "<td>" . $row['Firstname'] . "</td>";
echo "<td>" . $row['Lastname'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
PHP_PDO
最新推荐文章于 2023-12-21 17:02:37 发布