apache/php/mysql - guarenteed DB transaction

From: Date: Wed, 04 Feb 2004 15:33:11 +0000
Subject: apache/php/mysql - guarenteed DB transaction
Groups: php.db 
Request: Send a blank email to php-db+get-32783@lists.php.net to get a copy of this message
Hi all. Question on running in a config with Apache2,PHP 4.3.4,MySQL 4.0.17 running on Linux Redhat 9.0. Basically I want to make sure that a DB insert or update is guarenteed to complete. So if a user hits submit on a webpage, the transaction under the hood completes, no matter if the user hits cancel or his browser dies or whatever. (Not sure how to even test this condition, but I know it will happen) Below is a sample of my PHP which does one thing, simple insert into mysql. I am using MyISAM table types, and would like to maintain this if possible. Any help or pointers would be greatly appreciated. David whynotpizza@hotmail.com <?php // mysqltest.php // Main Variables $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "test"; // open persistent DB connection $dbcnx = @mysql_pconnect($dbhost, $dbuser, $dbpass) or die("The site database appears to be down."); if ($db!="" and !@mysql_select_db($db)) die("The site database is unavailable."); // Open DB Persistent Connection $dbcnx = dbPConnect(); // Execute check against database mysql_select_db($dbname, $dbcnx); // Create SQL $sql = "INSERT INTO mytable SET field1='update to field1',field2='update to field2'"; // // Execute SQL // $result = mysql_query($sql); // $result = 1 if success if ($result == '1') { echo "Finished with DB insert"; } else { echo "Failed."; } ?>

« previous php.db (#32783) next »