MySQL transactions doesn't work with included files?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Stenberg

    MySQL transactions doesn't work with included files?

    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("ST ART TRANSACTION", $db);
    mysql_query("IN SERT INTO news VALUES (NOW(),'author' ,'message from main
    script')", $db);

    include "test2.php" ;

    mysql_query("CO MMIT",$db);
    mysql_close($db );
    ?>

    and the included one (test2.php):
    <?PHP
    mysql_query("IN SERT 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
  • Marcin Dobrucki

    #2
    Re: MySQL transactions doesn't work with included files?

    Jan Stenberg wrote:[color=blue]
    > 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:[/color]
    ....[color=blue]
    > Does not make any sence for me. I hope someone can help to solve this.[/color]

    Did you copy&paste the script as was, or retype it? made a simple
    test, and it works fine. The only thing I can think of being wrong is
    the privileges for 'dbuser'.

    Jan, send me email directly, no point bouncing snippets back and
    forth here.

    /marcin

    Comment

    Working...