note 88838 added to mysqli.rollback
| From: | Lorenzo-webmasterAT4tourDOTit at osu1 dot php dot net | Date: | Tue, 10 Feb 2009 14:31:00 +0000 |
| Subject: | note 88838 added to mysqli.rollback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150449@lists.php.net to get a copy of this message | ||
This is an example to explain the powerful of the rollback and commit functions.
Let's suppose you want to be sure that all queries have to be executed without errors before
writing data on the database.
Here's the code:
<?
$all_query_ok=true; // our control variable
//we make 4 inserts, the last one generates an error
//if at least one query returns an error we change our control variable
$mysqli->query("INSERT INTO myCity (id) VALUES (100)") ? null : $all_query_ok=false;
$mysqli->query("INSERT INTO myCity (id) VALUES (200)") ? null : $all_query_ok=false;
$mysqli->query("INSERT INTO myCity (id) VALUES (300)") ? null : $all_query_ok=false;
$mysqli->query("INSERT INTO myCity (id) VALUES (100)") ? null : $all_query_ok=false;
//duplicated PRIMARY KEY VALUE
//now let's test our control variable
$all_query_ok ? $mysqli->commit() : $mysqli->rollback();
$mysqli->close();
?>
hope to be helpful!
----
Server IP: 80.241.173.254
Probable Submitter: 81.208.45.5
----
Manual Page -- http://www.php.net/manual/en/mysqli.rollback.php
Edit -- https://master.php.net/note/edit/88838
Del: integrated -- https://master.php.net/note/delete/88838/integrated
Del: useless -- https://master.php.net/note/delete/88838/useless
Del: bad code -- https://master.php.net/note/delete/88838/bad+code
Del: spam -- https://master.php.net/note/delete/88838/spam
Del: non-english -- https://master.php.net/note/delete/88838/non-english
Del: in docs -- https://master.php.net/note/delete/88838/in+docs
Del: other reasons-- https://master.php.net/note/delete/88838
Reject -- https://master.php.net/note/reject/88838
Search -- https://master.php.net/manage/user-notes.php