-1

所以我正在尝试使用 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)

?>  
4

1 回答 1

1

尝试更改为您的 PDO 连接$dbh,而不是$stuff在调用该函数时 -

getResults($dbh)
于 2013-05-01T19:37:02.070 回答