How to Create PHP PDO MySQL Connection

Here’s how I create a PDO connection to a MySQL database.

$dbh = new PDO('mysql:host=localhost;dbname=myfunkydata', 'dbusername', 'dbpassword');
$dbh->beginTransaction();
$sth = $dbh->prepare("INSERT INTO recording(name, date) VALUES(?, ?)");
$file = time();
$sth->execute(array($file, date('Y-m-d H:i:s', $file)));
$dbh->commit();
Share Button