所以我正在尝试使用 PDO 来查询数据库并返回结果。我一直在关注 php 手册并查看此站点,但我没有找到解决问题的方法。基本上,当我运行下面的代码时,我没有得到任何结果,什么都没有;只是一个空白页。我设置了 php 来显示错误,但没有返回任何错误。这是我的代码:
<?php
ini_set('display_errors', 'on');
//this is where you put the login information:
$username = "my.user.name";
$password = "my.password";
$hostname = "localhost";
//this connects to the database:
$dbh = new PDO('mysql:host=localhost;dbname=first_base', $username, $password);
//this selects the data from the table(s)
function getResults($stuff) {
$stmt = "SELECT name, date, type, location FROM information ORDER BY name";
foreach($stuff->query($stmt) as $row) {
print $row['name'];
print $row['date'];
print $row['type'];
print $row['location'];
}
}
getResults($stuff)
?>