PDO connection
Posted by: humanbeing (---.houston.res.rr.com)
Date: February 24, 2007 02:20AM

try {
$dbh = new PDO('mysql:host=localhost;dname=csh', 'user', 'psswd');

if ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
echo "Running on mysql; \n";
} else {
echo "Not runiing mysql";
}

$stmt = $dbh->prepare('SELECT * FROM a_employees');
$stmt->execute();
print("PDO::FETCH_ASSOC: "winking smiley;

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
$stmt = null;

// close the connection
$dbh = null;
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

Why does the code above return no results. I know that I'm connected since I get the "Running on mysql. Interesting that $row is always (null) so the while statement does not seem to get processed. I'm knew to PHP and buidling my first database driven website.

Is there more ways to verify that I'm connected to the database. Like return and print all the tables in the database?

Thanks,

Options: ReplyQuote


Sorry, only registered users may post in this forum.