Skip to content

Instantly share code, notes, and snippets.

@cjwfuller
Created April 3, 2013 14:04
Show Gist options
  • Save cjwfuller/5301489 to your computer and use it in GitHub Desktop.
Save cjwfuller/5301489 to your computer and use it in GitHub Desktop.
php-pdo MySQL connection
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment