Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 10:59 PM   #1
Giovanni R.
 
Giovanni R.'s Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default What if two or more users run the queries at the same moment?


I'm using PHP with the PDO functions to access to a MySQL database.

I've a table 'Projects' with an autoincrementing 'id' and a table
'Categories' which stores the categories the project belongs to.

When I've to insert a new project into the db, I run this query:

I) INSERT INTO Projects (id, ...) VALUES (NULL, ...);

Then I take the id inserted using PDO::lastInsertID() and run this one:

II) INSERT INTO Categories (id_project, ...) VALUES ($last_id, ...);

My question is: what if two or more users will submit a new project at
the "same" moment?

Let's imagine this is the temporal sequence:

1) the first one runs the (I) query (eg. new ID = 10);
2) the second one runs the (I) query (eg. ID = 11);
3) the first one runs the (II) query, using PDO::lastInsertID();
4) the second one runs the (II) query, using PDO::lastInsertID();

Will PDO::lastInsertID() return 11 or (correctly) 10 at the moment #3?

In general, which is the best way to make a set of queries be executed
in a "serial" way?

I'd like that the first user runs the (I) and the (II) queries and only
at the end the second user will start running the (I) query.

Is it possible to do that?

Thanks!
Giovanni

ps. I'm already using PDO::beginTransaction() and PDO::commit().

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 07-01-2007, 10:59 PM   #2
Captain Paralytic
 
Captain Paralytic's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default What if two or more users run the queries at the same moment?

On 5 Jun, 14:21, "Giovanni R." <gie...@askme.it> wrote:
> I'm using PHP with the PDO functions to access to a MySQL database.
>
> I've a table 'Projects' with an autoincrementing 'id' and a table
> 'Categories' which stores the categories the project belongs to.
>
> When I've to insert a new project into the db, I run this query:
>
> I) INSERT INTO Projects (id, ...) VALUES (NULL, ...);
>
> Then I take the id inserted using PDO::lastInsertID() and run this one:
>
> II) INSERT INTO Categories (id_project, ...) VALUES ($last_id, ...);
>
> My question is: what if two or more users will submit a new project at
> the "same" moment?
>
> Let's imagine this is the temporal sequence:
>
> 1) the first one runs the (I) query (eg. new ID = 10);
> 2) the second one runs the (I) query (eg. ID = 11);
> 3) the first one runs the (II) query, using PDO::lastInsertID();
> 4) the second one runs the (II) query, using PDO::lastInsertID();
>
> Will PDO::lastInsertID() return 11 or (correctly) 10 at the moment #3?
>
> In general, which is the best way to make a set of queries be executed
> in a "serial" way?
>
> I'd like that the first user runs the (I) and the (II) queries and only
> at the end the second user will start running the (I) query.
>
> Is it possible to do that?
>
> Thanks!
> Giovanni
>
> ps. I'm already using PDO::beginTransaction() and PDO::commit().


The second user will be running with a different connection. They will
get their last insert id, you will get yours.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-01-2007, 10:59 PM   #3
Giovanni R.
 
Giovanni R.'s Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default What if two or more users run the queries at the same moment?

Captain Paralytic wrote:

> The second user will be running with a different connection. They will
> get their last insert id, you will get yours.


Ok, I'll trust you. :-)

Thanks.
Giovanni

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-01-2007, 10:59 PM   #4
Captain Paralytic
 
Captain Paralytic's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default What if two or more users run the queries at the same moment?

On 5 Jun, 15:35, "Giovanni R." <gie...@askme.it> wrote:
> Captain Paralytic wrote:
> > The second user will be running with a different connection. They will
> > get their last insert id, you will get yours.

>
> Ok, I'll trust you. :-)
>
> Thanks.
> Giovanni


Trust the manual:
http://dev.mysql.com/doc/refman/5.0/...insert-id.html

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: , , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Funny moment in the bonus DVD David Vestal Console Subjects 1 06-26-2007 2:06 PM
Correcting queries James Walker Database 0 05-31-2007 8:37 PM
Best TFT out at the moment Gamer Noob Video Cards and Monitors 1 10-26-2006 9:57 AM
Looking for any handy SQL queries Whatcha Database 10 07-10-2006 6:59 AM
Best psp games on the market at the moment MadKad Console Subjects 9 06-25-2006 2:46 AM


Featured Websites




All times are GMT +1. The time now is 3:28 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98