![]() |
|
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. |
| |||||||
| 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. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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(). | |||
|
| Advertisements |
| | #2 | ||
| 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. | |||
|
| | #3 | ||
| 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 | |||
|
| | #4 | ||
| 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 | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: moment, queries, run, same, two, users |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
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 | ||||
|