CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Getting the most accurate last inserted key

Print topic Send  topic

Author Message
Koren

Posts: 83
Posted: 04/20/2007, 11:56 AM

I have a table that will be updated all the time by MANY users.
Once data is inserted into the table I need to extract the last inserted key and store it in a variable. I have used the famous
   
 $xxx = CCDLookUp("max(field_id)","tablel","", $DBConnection1);;  
in other record forms, but this one will require something much more accurate.
My understanding is that the MYSQL command:
  
SELECT LAST_INSERT_ID();  
might be the way to go. I was reading that in order to get the best results the LAST_INSERT_ID() query has to be run within the same DBconnection. So, this brings me to my question. Can I run
  
$pk =  CCDLookUp("LAST_INSERT_ID()", "", "", $DBConnection1)  
 
in the AFTER insert to get the accurate result.
OR would this produce 1 separate connections?
Thanks So Much!
View profile  Send private message
damian

Posts: 838
Posted: 04/22/2007, 6:16 AM

When I need to get the most recent entry by the current user I use the PHP command mysql_insert_id() (same as the mysql one, but it runs un the php side of things). I retrieve the value and stick it in a SESSION for future use - eg:

$NewClientID = mysql_insert_id();
CCSetSession("myClientID", $NewClientID);

I can retrieve this then on any subsequent page until I redo the initial page.

Damian


_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.