Created
March 15, 2012 18:04
-
-
Save armno/2045717 to your computer and use it in GitHub Desktop.
Simple Data Insertion using PHP PDO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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