eratech
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:
mysqli_insert_id()
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:
mysqli_insert_id($Component->DataSource->Link_ID)
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
Eric
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia |
|
|
DataDoIT
|
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.
|
|
|
|