473,814 Members | 3,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql_insert_id ()

134 New Member
hi

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

and to get the inserted id(auto_increme nted 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 2862
Dormilich
8,658 Recognized Expert Moderator Expert
@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 New Member
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 Recognized Expert Expert
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
41949
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" that would be populated with a unique number upon insertion... How can I get the unique number it assigned to that record returned for futher use?
0
2401
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 . I've those two piece of code, the first is part of a class: --------- function connect($layer,$host,$db_port,$db_name,$user,$pass) { $dsn = "$layer://$user:$pass@$host:$db_port/$db_name";
1
1910
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 (".mysql_insert_id().");"; } to something where only two sql queries are made (as opposed to 100?). ie. where the first line could be converted to something like this:
2
1541
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 immediately need the auto_incremented Key-ID of the new record to put other information in related tables. In the past i've gotten that ID by just doing a SELECT with a WHERE that matches all the values i've just INSERTED, but it seems a cumbersome...
6
4691
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 by mysql_insert_id() function. However, the problem is that my web site can visit many users and many of them can initiate the describe procedure. It can happen that between the first user inserts something into database and executes...
3
2274
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 the initial insert by the first user but b4 the insert_id part can be queried. Regards
2
1533
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 offer foreign key feature on tables,so what I did is stick the corresponding submission id in the member's uploaded file when renaming the file. Each member can upload up to 6 files. Now,I'm clueless how to retrieve those matching images(or just 1...
3
12449
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 insert a record and return the inserted record id. (each record will insert by a unique id).
1
2920
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 autoincrement (my primary key) when using a stored procedure? Thanks.
0
9609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10426
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10141
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7686
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5707
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.