Skip to content

Instantly share code, notes, and snippets.

Created Mar 15, 2012
What would you like to do?
Simple Data Insertion using PHP PDO
$hostname = 'localhost';
$username = 'root';
$password = 'root';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=prod", $username, $password);
echo 'Connected to database';
$id = sha1(time());
$ds = 'content';
$created = time();
$data = array($id, $ds, $created);
$s = $dbh->prepare('INSERT INTO provider_data (id, data_string, created) VALUES(?,?,?)');
$count = $s->execute($data);
echo $count;
catch(PDOException $e)
echo $e->getMessage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment