Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Transactions and auto increment table rows
Old 02-27-2008, 11:07 AM Transactions and auto increment table rows
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Hi

can a php page be used by 2 people at the same time or will one page load be completed before another person can call it?

I have a registration form which, when processed will update several tables at once. Nothing new there, but ive come accross something which i feel could ultimately be a problem and that is a very common procedure. it goes like this -

my user table has a userid field which is auto increment, and my images table has a userid id field which is not auto increment. During a transaction i add a row to my user table, which auto increments the userid column, then before i confirm the transaction i need to enter the user's image information and tie it to the user table with the userid which has just been assigned to the user table.

my transaction would look something like this -

BEGIN TRANSACTION

ENTER USER TABLE INFO

SELECT RECENT USERID FROM USER TABLE

(increment userid as the entry above hasnt been confirmed yet)
$userid=($userid+1)

ENTER IMAGES TABLE INFO WITH $userid as key

CONFIRM OR DECLINE TRANSACTION

What would happen if 2 people submitted their registration forms within nano seconds of one another and the SELECT USERID query of user 2 retrieved the userid of user 1 whos transaction had been confirmed between the ENTER USER TABLE query and the SELECT USERID query of user 2?

I hope this makes some sense. Its a very simple concept that i have difficulty explaining.

thanks in advance

mark

Last edited by hiptobesquare; 02-27-2008 at 11:12 AM..
hiptobesquare is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-27-2008, 04:10 PM Re: Transactions and auto increment table rows
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
It's all handled by the server, as long as your have a normal server and aren't trying to do it with 64K RAM or something you shouldn't face an issue because it'll handle it fast enough. From what I see you have something like:
PHP Code:
$query "insert into user_table values(NULL)";
$result mysql_query($query);
$idget "select user_id from user_table sort by user_id DESC limit 1";
$getid mysql_query($idget);
$userid mysql_fetch_array($getid);
$userid $userid[0];
$picput "insert into pic_table values('$userid',$img)";
$putpic mysql_query($picput); 
That would all be run as the page was parsed, let's call the users user_1 and user_2. When user_1 requests that to be parsed it starts parse_job_1 user_2 then asks for it to be parsed and it queues parse_job_2 until parse_job_1 finishes. Then it'll run parse_job_2. Now then if you're reloading the page etc then you could have an issue there.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 02-28-2008, 04:44 AM Re: Transactions and auto increment table rows
Ultra Talker

Posts: 310
Trades: 0
Don't use a separate query for retreiving the user id, use mysql_insert_id function.
dman_2007 is offline
Reply With Quote
View Public Profile
 
Old 02-28-2008, 05:50 AM Re: Transactions and auto increment table rows
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
i know its very unlikely to happen arenlor, but it only needs to happen once to wreak a fair bit of havoc which is quite difficult to rectify afterwards.

the mysql_insert_id function is exactly what i was looking for thanks dman.
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Transactions and auto increment table rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44223 seconds with 12 queries