Created
March 11, 2016 00:21
-
-
Save zyphlar/146a4a73d381defc57f3 to your computer and use it in GitHub Desktop.
pdo example
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 | |
//.. | |
$foo = "foofoo"; | |
$bar = "barbar"; | |
$conn = new PDO('mysql:host=yourserverip;dbname=yourdatabasename', 'username', 'password'); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
foreach (...) { | |
$sth = $conn->prepare("INSERT INTO db (foo,bar) VALUES (:foo, :bar)"); | |
$sth->bindParam(':foo', $foo); | |
$sth->bindParam(':bar', $bar); | |
$sth->execute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment