Skip to content

Instantly share code, notes, and snippets.

@zyphlar
Created March 11, 2016 00:21
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 zyphlar/146a4a73d381defc57f3 to your computer and use it in GitHub Desktop.
Save zyphlar/146a4a73d381defc57f3 to your computer and use it in GitHub Desktop.
pdo example
<?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