Res: apache/php/mysql - guarenteed DB transaction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
 
Hi,
I had a similar problem and I solved it using transations, but I had to use InnoDB table types...
 
Regards,
Ricardo 
 
-------Mensagem original-------
 
Data: 02/04/04 15:33:37
Assunto: apache/php/mysql - guarenteed DB transaction
 
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
 
 
 
<?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.";
  }
 
?>
 
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
 
 
____________________________________________________
  IncrediMail - O mundo do correio eletrônico finalmente desenvolveu-se - Clique aqui

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux