User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,492 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1670 | Replies: 3
Reply
Join Date: Sep 2007
Posts: 18
Reputation: tomjohnson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tomjohnson tomjohnson is offline Offline
Newbie Poster

How to use multiple inserts with transactions in mysql

  #1  
Oct 20th, 2007
Hello everyone,

I have a bit of a problem. I am in the middle of developing a site that needs to use transactions. I have several different tables that comprise a single insert form. Table A, B and C all require transactions.

From what I understand, mysql_query does not support multiple queries. I have several problems that I will list.

1. autocommit is turned off and my script needs to issue "COMMIT"
2. mysql_insert_id() will NOT get the last id until the COMMIT has been issued so returns false.

Basically, I cannot insert data into table B without first knowing the last_id from table A.

I can't get around how to accomplish this.

Can someone please give a hand?

Thanks,

Tom
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is online now Online
Practically a Master Poster

Re: How to use multiple inserts with transactions in mysql

  #2  
Oct 20th, 2007
put the results from a query from table A into an array and get the total number of results using to count() function. take that number and subtract 1 from it. put that number here:

ex.
$array = $array[$number];

then use that variable in table B's query
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: How to use multiple inserts with transactions in mysql

  #3  
Oct 20th, 2007
did you try to insert empty record then assign it

for example:
$RecID = '1001';

$Table1 = "your sql code where ID=$RecID";
mysql_query($Table1);
$Table2 = ....
...
$Table3 = ....
....

on error, delete the record

i do in this way.
Last edited by fatihpiristine : Oct 20th, 2007 at 4:20 pm.
Do a favour, leave me alone
Reply With Quote  
Join Date: Sep 2007
Posts: 18
Reputation: tomjohnson is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
tomjohnson tomjohnson is offline Offline
Newbie Poster

Re: How to use multiple inserts with transactions in mysql

  #4  
Oct 20th, 2007
Hey guys,

Thanks for the response.. These are really good ideas and I am going to try and implement them. I will post back and let you huys know how it went.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC