Posts Tagged: PDO

How to Insert Data with PHP PDO

Here’s one way to insert a record using PHP PDO into 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();

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();