CodeCharge Studio
search Register Login  

Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 get autoinc value

Print topic Send  topic

Author Message
bill
Posted: 01/02/2010, 10:25 AM

I need a safe way to retrieve lastid from a customers table - custid autoinc
so I need to find the correct entry (cust_name is unique).
With multiple people updating I don't mysql_insert_id would be safe.

So I've tried this

$lastid =
CCDLookup("cust_id","customers","cust_name=".$db->ToSQL($Component->cust_name->GetValue(),
ccsText),$db);

With above $lastid seems to be null!

I searched the forums and found some example - so also tried

$SQL = "SELECT cust_id FROM customers WHERE cust_name= '$cust_name'";
$db->query($SQL);
$custid = $db->f(0);

but echo $SQL shows up as SELECT cust_id FROM customers WHERE cust_name=
NULL

datadoit
Posted: 01/02/2010, 2:37 PM

Bill, it completely depends on -WHEN- you're attempting to get the last
inserted record for a field that is auto incremented. In CodeCharge,
you do this in the AfterInsert or AfterExecuteInsert events, and if
you're using PHP, then you SHOULD BE using the mysql_insert_id()
function. It is 99.9% full-proof, regardless of how many users are on
your system. We've run systems with thousands of users across clusters
with nary an issue for years.

Ex: All of our Insert Record forms will grab that last inserted id in
the AfterInsert event, and we subsequently redirect the user back to
that record form, but this time in edit mode instead of insert mode.

global $Redirect, $FileName;
$last_id = mysql_insert_id();
if ($last_id) {
$Redirect = $FileName . "?id=" . $last_id;
}



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.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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