-1

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)

?>  

1 Answers1

1

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

getResults($dbh)
Sean
  • 12,443
  • 3
  • 29
  • 47
  • 2
    Now they'll tell you 'wow whoops variable is all right'. That's what a call *not a real* question – Your Common Sense May 01 '13 at 19:38
  • 1
    that fixed it. the php manual doesn't say that is necessary or to even do that. I really appreciate your help. – user2288315 May 01 '13 at 19:55
  • Take a look at [Function arguments - http://php.net/manual/en/functions.arguments.php](http://php.net/manual/en/functions.arguments.php) and [Variable scope - http://php.net/manual/en/language.variables.scope.php](http://php.net/manual/en/language.variables.scope.php) from the php docs to understand why this is neccessary – Sean May 01 '13 at 20:17