CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 Better handling for mysqli_insert_id with Link_ID

Print topic Send  topic

Author Message

Posts: 513
Posted: 11/06/2014, 6:18 PM

A tip that might be useful if your mysqli_insert_id() is failing (this might also work for old mysql_insert_id too)

My code that had previously been working for months was failing to retrieve the last ID from a regular INSERT. I was collecting the ID in the 'AfterExecuteInsert' event with an Action of 'Declare Variable' and setting the default to:


After googling there is the optional '$link' parameter which will make it much more likely it will return the correct ID. I found the Link_ID details after digging through the db_mysqli.php and changed it to:


So my full AfterExecuteInsert looks like this, for the 'employees' Record:

//employees_ds_AfterExecuteInsert @2-0F06CAE5
function employees_ds_AfterExecuteInsert(& $sender)
$employees_ds_AfterExecuteInsert = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $employees; //Compatibility
//End employees_ds_AfterExecuteInsert

//Declare Variable @66-7A87400E
global $latest_insert_id;
$latest_insert_id = mysqli_insert_id($Component->DataSource->Link_ID);
//End Declare Variable

//Close employees_ds_AfterExecuteInsert @2-DAAF0C58
return $employees_ds_AfterExecuteInsert;
//End Close employees_ds_AfterExecuteInsert

Hope it helps

CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message
Posted: 03/26/2016, 11:14 AM

Given the latest CCS update .18992 and Improved MySQL (mysqli), this new
method for retrieving the last inserted ID is required.

+1 Eric.

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

PHP Reports

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

Home   |    Search   |    Members   |    Register   |    Login

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