Re: [PHP-DB] Help: Transactions not working
John, Big thank you! for your help. I had been trying out the mysql_insert_id and was not having luck. It's working great (with just a few more bumps to get over). --- John Holmes <[EMAIL PROTECTED]> wrote: > Stuart Felenstein wrote: > > > But - I want to confirm, am I still using > transactions > > even though I'm issuing individual query calls for > > each insert. > > Yes, that's the idea. Everthing between BEGIN and > COMMIT/ROLLBACK is the > transaction. > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Help: Transactions not working
That made a world of difference! :) Thank you. But - I want to confirm, am I still using transactions even though I'm issuing individual query calls for each insert. And, if I can ask another question to the list : In this line (from the second insert) VALUES (null, LAST_INSERT_ID(), ..)"; The LAST_INSERT_ID works great here, getting the auto-inc from the first insert, but will it work in subsequent insertions to other tables. I ask because in the second insert (shown), the LAST_INSERT_ID, gets the value from the first table, but the second table (second insert) also has an auto-inc column. So I'm thinking then the third insert will get the LAST_INSERT_ID from table 2 / 2nd insert. Perhaps I need to declare it the first time as a value (app code) or add "where" conditions to all the subsequent insertions ? Thank you, Stuart --- John Holmes <[EMAIL PROTECTED]> wrote: > > Am I missing something here ? > > Yep... you're missing a mysql_query() call for each > query. You're only > running one query and echoing the other... > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Help: Transactions not working
Stuart Felenstein wrote: 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 ? Yep... you're missing a mysql_query() call for each query. You're only running one query and echoing the other... $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; $result = mysql_query($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); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Help: Transactions not working
Stuart Felenstein wrote: But - I want to confirm, am I still using transactions even though I'm issuing individual query calls for each insert. Yes, that's the idea. Everthing between BEGIN and COMMIT/ROLLBACK is the transaction. In this line (from the second insert) VALUES (null, LAST_INSERT_ID(), ..)"; The LAST_INSERT_ID works great here, getting the auto-inc from the first insert, but will it work in subsequent insertions to other tables. I ask because in the second insert (shown), the LAST_INSERT_ID, gets the value from the first table, but the second table (second insert) also has an auto-inc column. So I'm thinking then the third insert will get the LAST_INSERT_ID from table 2 / 2nd insert. Yes, that's what will happen. LAST_INSERT_ID() picks up the last auto_increment number created. Perhaps I need to declare it the first time as a value (app code) or add "where" conditions to all the subsequent insertions ? You can get the auto_increment number using mysql_insert_id(), save it in a variable and then use that in subsequent queries. $query1 = "INSERT INTO ... "; $id = mysql_insert_id(); $query2 = "INSERT INTO (id,...) VALUES ($id,...)"; $query3 = "INSERT INTO (id,...) VALUES ($id,...)"; etc... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php