473,815 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is mysql_insert_id safe

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

Marc

Jun 13 '06 #1
3 2274
Rik
monomaniac21 wrote:
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.


No, mysql_insert_id () in the same script always gets the value of the last
query performed by that specific script, not by other connections to the
database.

Grtz,
--
Rik Wasmus
Jun 13 '06 #2
"monomaniac 21" <mc******@googl email.com> wrote in
news:11******** **************@ f6g2000cwb.goog legroups.com:
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.


You won't have any problems if you're running it immediately after the
query.

--
Karl Groves
www.karlcore.com
Jun 13 '06 #3
>> 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.


You won't have any problems if you're running it immediately after the
query.


In the database world, there is no "immediatel y after". It's always
possible for someone else to get in a query between any two of
yours. It's up to locking (implicit or explicit) or transactions
to prevent bad effects on the data from this by delaying execution
of one until another finishes.

mysql_insert_id () returns the last insert id ON THIS CONNECTION.
So, as long as you keep the connection open (which probably won't
be beyond the processing of the PHP page: with persistent connections,
you are NOT guaranteed to get the same connection next time), you
can wait as long as you want to call mysql_insert_id ().

Gordon L. Burditt
Jun 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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:
9
4123
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the PrintDialog control under a security setting with only SafePrinting allowed. I have attached a sample project that I am using to try to accomplish this. The print dialog appears, but when I press the Print button, I get an exception (at the end...
11
2259
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe." I have 2 questions: 1. I thought dynamic variables are thread-safe since threads have their own
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...
1
3604
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in some files and work on it. Let say, I want add new page to web project named websiteOrder.sln, i will open websiteOrder.sln in my local computer, connected to websiteOrder.sln located in Visual Source Safe 6.0(source safe located in another...
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...
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.
3
2863
by: vjayis | last post by:
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? <? mysql_query(“insert into table(name,value) values('$name','value')”);
0
10672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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
10427
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
9225
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
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...
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.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.