Help: Transactions not working

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

 



If you see the code I have the begin , then the $query
follows.  With both statements present, only the
second one does the insert. If I // or remove the
second, the first one takes.  

Am I missing something here ?

Stuart

Code:

function begin()
{
mysql_query("BEGIN");
}
function commit()
{
mysql_query("COMMIT");
}
function rollback()
{
mysql_query("ROLLBACK");
}
mysql_connect("...relevant information") or
die(mysql_error());
$link = mysql_connect("...relevant information"); 
mysql_select_db("database", $link) or
die(mysql_error());
echo mysql_errno($link) . ": " . mysql_error($link).
"\n";

begin(); // transaction begins

$query = "INSERT INTO Profiles (ProfileID, UserID,
ProfileName,
Edu, WorkAuth, WorkExp, CarLev, Secu, Confi, Relo,
Telecomu, 
City1, State1, City2, State2, TravelPref,
SalaryAnnual, SalaryHourly, Available)
VALUES (null, null, '$f1a', $f2a, $f2c, $f2d, $f2e,
$f2g, '$f5b', '$f3m',
'$f3n', '$f3e', $f3f, '$f3g', $f3h, $f3i, $f3j, $f3k,
$f3l)";

echo $query;

$query = "INSERT INTO LurkProfiles_AddContacts
(AddContID, ProfileID, P1,
P2, Pgr, Eml2, Eml3)
VALUES (null, LAST_INSERT_ID(), '$f1b', '$f1c',
'$f1d', '$f1e', '$f1g')";

echo $query;

$result = mysql_query($query);


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";

}
printf("Last inserted record has id %d\n",
mysql_insert_id());
?>

-- 
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