Skip to content

Instantly share code, notes, and snippets.

@albertein
Created June 4, 2012 01:18
Show Gist options
  • Save albertein/2865748 to your computer and use it in GitHub Desktop.
Save albertein/2865748 to your computer and use it in GitHub Desktop.
PDO transactions + prepared statemes
$dbh->beginTransaction();
$statement = $dbh->prepare("INSERT INTO TABLE (field1, field2) VALUES (:v1, :v2)");
$stmt->bindParam(':v1', $value1);
$stmt->bindParam(':v2', $value2);
for ($i = 0; $i < 300; $i++) {
$value1 = 'value';
$value2 = 'another value';
$stmt->execute();
}
$dbh->commit();
//On error should call $dbh->rollback();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment