troubleshooting Question

Getting Output of LAST_INSERT_ID() in PHP and PDO

Avatar of Confused Coder
Confused Coder asked on
PHPMySQL Server
25 Comments1 Solution996 ViewsLast Modified:
Here is my problem, i have a stored Procedure that creates a new customer and i call it from my RestAPI which works fine. So that
the User can make changes etc i need the CustomerId of the new record i just created. the Customerid is an Autoincrement field
so it is supported via the "LAST_INSERT_ID()" my stored procedure works fine when i call it from my workbench, my issue is how to
call it form PHP when using PDO.
$sth = $this->db->prepare('CALL `oss`.`sp_customer_insert`(?,?,?,?)');

            $sth->bindParam(1, $data->quicken_id, PDO::PARAM_STR, 20);
            $sth->bindParam(2, $data->old_id, PDO::PARAM_STR, 25);
            $sth->bindParam(3, $data->status, PDO::PARAM_STR, 10);
            $sth->bindParam(4, $data->name, PDO::PARAM_STR, 60);
$sth->execute();
So question is where and how do i specify the output field in my prepare statment and how do i retrieve the value of LID
since mysql does not return it by default
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 25 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 25 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros