473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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("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
Jul 17 '05 #1
1 1826
Jan Stenberg wrote:
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: .... Does not make any sence for me. I hope someone can help to solve this.


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
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
5
by: princevejita1 | last post by:
Hello I have problem with my MySQL server and transactions. I installed MySQL server 5.0.11 with MySQL administrator & MySql Query Browser on Win XP Prof. I would like to use transactions, so I...
0
by: Christopher DeMarco | last post by:
Hi all... ...I've got a Python script running on a bunch of boxen sharing some common NFS-exported space. I need (not want :) to lock files for writing, and I need (not want :) to do it safely...
10
by: smorrey | last post by:
Hello all, this might better be suited for the MySQL newsgroup, but I figured I'ld post here and see if anyone can help me. I'm trying to create a simple transaction handling system where users...
20
by: John Wells | last post by:
Yes, I know you've seen the above subject before, so please be gentle with the flamethrowers. I'm preparing to enter a discussion with management at my company regarding going forward as either...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.