Dalexan
asked on
Inserting record and returning id of just inserted
What is the best practice for inserting a record from a php form submit and returning the id of the record inserted back to the form for use in other processes. The below code is what I'm currently using, just trying to determine whats the best practice. Another method would be to code the insert within a php begin-commit transaction block in the web form rather than use this stored proc.
PROCEDURE OrderCRM.`Sp_addneworderheader`(
INOUT v_orderid INT ,
v_cust_id INT,
v_bill_addr_id INT,
v_ship_addr_id INT,)
BEGIN
START TRANSACTION;
INSERT INTO order_header(
cust_id,
ord_bill_adr_id,
ord_ship_adr_id)
VALUES(
v_cust_id,
v_bill_addr_id,
v_ship_addr_id);
SET v_orderid = LAST_INSERT_ID();
select IFNULL(ord_id,0) INTO v_orderid
FROM order_header
WHERE ord_id=v_orderid;
COMMIT;
END;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I was looking for
Open in new window