Skip to content

Instantly share code, notes, and snippets.

@kitelife
Created March 17, 2014 14:31
Show Gist options
  • Select an option

  • Save kitelife/9600266 to your computer and use it in GitHub Desktop.

Select an option

Save kitelife/9600266 to your computer and use it in GitHub Desktop.
<?php
try {
$db_conn = new PDO('mysql:host=localhost;dbname=recipes', 'php-user', 'secret');
} catch (PDOException $e) {
echo "Could not connect to database";
exit;
}
try {
// start the transaction
$db_conn->beginTransaction();
$db_conn->exec('UPDATE categories SET id=17 WHERE name = "Pudding"');
$db_conn->exec('UPDATE recipes SET category_id=17 WHERE category_id=3');
// we made it!
$db_conn->commit();
} catch (PDOException $e) {
$db_conn->rollBack();
echo "Something went wrong: " . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment