How to use PDO to issue a query to a database and return the results?

So I am trying to use PDO to query a database and return the results. I have been following along with the php manual and looking on this site but I'm not seeing a solution to my problem. Basically when I run the code below I get no results, nothing; just a blank page. I have php set to show me errors but none are returned. Here is my code:

<?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)

?>  

Answers


Try changing to your PDO connection $dbh instead of $stuff when calling the function -

getResults($dbh)

Need Your Help

List of areas missing support for ECMAScript/JavaScript in major browsers?

javascript browser cross-browser ecmascript-5

Is anyone aware of a definitive list of areas of missing support for ECMAScript/JavaScript in the major browsers (I'm talking IE7+, Firefox, Chrome, Safari and Opera).

Jquery modal select issue

javascript jquery html5

I have a modal window with a select inside.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.