Created
March 17, 2014 14:31
-
-
Save kitelife/9600266 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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