You are here: MySQL transactions doesn't work with included files? « PHP Programming Language « IT news, forums, messages
MySQL transactions doesn't work with included files?

Posted by Jan Stenberg on 06/28/05 14:00

I have a situation where I open a database connection in main script.
Then I start a transaction, have some queries, include an another php
file within some queries and then commiting queries in the main script.
All queries in the main script gets committed but those in the included
file doesn't. Why's that? Adding COMMIT query to the included file
doesn't work either. Here are an test code which clears what I mean:

the main file (test.php):
<?PHP
$db = mysql_connect ("localhost", "dbuser", "dbpass") or die ("Database
connection error!");
mysql_select_db("databasename") or die ("Database selection error!");

mysql_query("START TRANSACTION", $db);
mysql_query("INSERT INTO news VALUES (NOW(),'author','message from main
script')", $db);

include "test2.php";

mysql_query("COMMIT",$db);
mysql_close($db);
?>

and the included one (test2.php):
<?PHP
mysql_query("INSERT INTO news VALUES (NOW(),'author2','message from the
included script')", $db);
?>


So, this script runs fine, but there is just one row inserted to db (the
one from the main script (test.php)). var_dump of $db in the included
script tells as it should: resource(2) of type (mysql link)

Tables are InnoDB type and START TRANSACTION and COMMIT both returns
true (1). I also made some error handlers but those were not trapped either.

Does not make any sence for me. I hope someone can help to solve this.

JS

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация