Created
November 10, 2010 07:24
-
-
Save shameerc/670494 to your computer and use it in GitHub Desktop.
PHP Pdo class
This file contains 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
<? | |
$dsn = 'mysql:dbname=test;host=hostname'; | |
$user = 'username'; | |
$password = 'Password'; | |
try { | |
$dbh = new PDO($dsn, $user, $password); | |
echo "Connected"; | |
} catch (PDOException $e) { | |
echo 'Connection failed: ' . $e->getMessage(); | |
} | |
$id = 1; | |
$sth = $dbh->prepare("SELECT * FROM testprepare where id = :id"); | |
$sth->bindParam(':id',$id, PDO::PARAM_INT); | |
$sth->execute(); | |
$result = $sth->fetchAll(); | |
print_r($result); | |
?> |
This file contains 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 | |
$insert = $dbh->prepare("INSERT INTO fruit(name, colour) VALUES (?, ?)"); | |
$insert->execute(array('apple', 'green')); | |
$insert->execute(array('pear', 'yellow')); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment