Transactions - working but unsure about steps

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

 



My statements are all working but I'm not sure if
things are set up correctly.  I say this because at
one point the first $query failed, yet the rest of
inserts wre committed.  Now I believe I need to set
autocommit to 0 , yet the query failed due to a syntax
error. Hence 0 records effected wouldn't be the case
here.
Here is what I have:

//Create these functions -
function begin()
{
mysql_query("BEGIN");
}
function commit()
{
mysql_query("COMMIT");
}
function rollback()
{
mysql_query("ROLLBACK");
}

connection statement with error checking...........

begin(); // transaction begins
$query = "INSERT INTO firsttable.....//first query
$result = mysql_query($query); // process first query
$query = "INSERT INTO secondtable...//second query
$result = mysql_query($query); // process second query
$query = "INSERT INTO thirdtable....//third query
$result = mysql_query($query); // process third query

then: 

if(!$result)
{
echo mysql_errno($link) . ": " . mysql_error($link).
"\n";
rollback(); // transaction rolls back

exit;
}
else
{
commit(); // transaction is committed
echo "your insertion was successful";

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

  Powered by Linux