473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

mysql_insert_id()

134 100+
hi

i have a form which inserts records into my table using php

and to get the inserted id(auto_incremented ID) can i use this command?

Expand|Select|Wrap|Line Numbers
  1. <?
  2. mysql_query(“insert into table(name,value) values('$name','value')”); 
  3.  
  4. echo "Auto increment ID is = ".mysql_insert_id(); 
  5. ?>
  6.  

if multiple users are using the same page and multiple datas are inserted at a single time ., will it return the unique Auto_increment ID for the particular record or will it return the last inserted id...

thanks
Sep 4 '09 #1
3 2841
Dormilich
8,658 Expert Mod 8TB
@vjayis
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
@vjayis
not possible, and even if 2 people could manage to make a request at the same microsecond, it will be queued (I think)

@vjayis
what does your logic tells you will happen?
Sep 4 '09 #2
charli
23
Hmm, the mysql documentation does use language thats a bit hazy on that doesn't it.

Mysql_insert_id() looks at the current connection, so should always returns the relevant value with no concurrency issues
Sep 4 '09 #3
Markus
6,050 Expert 4TB
Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.
Now, are multiple connections from PHP considered 'multiple clients'?

Maybe a question for MySQL forum.
Sep 4 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Sugapablo | last post by:
Let's say I create a new record in a table like this: mysql_query("INSERT INTO table (col1) VALUES ('example')",$conn); ....that had an auto-incrementing, unique identifying column named "ID"...
0
by: kain | last post by:
hi there, I'm currently converting a MySQL application to PostgreSQL, and I hacked this app to support PEAR::Db . after some good coding days, I've found a problem: mysql_insert_id on pear::db ....
1
by: yawnmoth | last post by:
how could i reduce the following piece of code: for ($num=0;$num<50;$num++) { mysql_query($db,"INSERT INTO whatever (stuff) VALUES (somevalue);"; mysql_query($db,"INSERT INTO sometable VALUES...
2
by: Ravenslay3r | last post by:
I'm making a web-site thats backended by php-2-mysql. A common problem seems to be when processing form data, I use information early in the form to create a new record in a main table. I then...
6
by: opt_inf_env | last post by:
Hi, I would like to insert a data (row) into database (MySQL) and than to generate file whose name contains the ID of the inserted row (ID is declared as AUTO_INCREMENT). I wanted to extract ID...
3
by: monomaniac21 | last post by:
Hi all With regard to mysql's mysql_insert_id function is it possible that the query can return the insert id from another insert performed by a another user of the database which occured after...
2
by: Jankie | last post by:
Hi and wish all moderators and members are doing well i Back with a question after a long while,hope to find the valuable typical support from thescripts people and members. My host does not...
3
by: svsenthilkumar | last post by:
Hai, i want to insert a record and retrieve id using php-mysql. i want insert a record by copy of another one table. after inserting i update a field in the inserted record. so, can i...
1
by: Fred | last post by:
if my query is a regular INSERT, then mysql_insert_id() works as expected. But if I use a Stored Procedure to do my insert, then mysql_insert_id() returns 0 How can I get a returned...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.