Skip to content

Instantly share code, notes, and snippets.

@armno
Created March 15, 2012 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armno/2045717 to your computer and use it in GitHub Desktop.
Save armno/2045717 to your computer and use it in GitHub Desktop.
Simple Data Insertion using PHP PDO
<?php
$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