note 88857 added to mysqli.commit

From: Date: Wed, 11 Feb 2009 11:12:53 +0000
Subject: note 88857 added to mysqli.commit
Groups: php.notes 
Request: Send a blank email to php-notes+get-150473@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: <?php $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: 213.92.11.19 Probable Submitter: 81.208.45.5 ---- Manual Page -- http://www.php.net/manual/en/mysqli.commit.php Edit -- https://master.php.net/note/edit/88857 Del: integrated -- https://master.php.net/note/delete/88857/integrated Del: useless -- https://master.php.net/note/delete/88857/useless Del: bad code -- https://master.php.net/note/delete/88857/bad+code Del: spam -- https://master.php.net/note/delete/88857/spam Del: non-english -- https://master.php.net/note/delete/88857/non-english Del: in docs -- https://master.php.net/note/delete/88857/in+docs Del: other reasons-- https://master.php.net/note/delete/88857 Reject -- https://master.php.net/note/reject/88857 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150473) next »