Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get inserted record w/ perl+dbi+mysql

Status
Not open for further replies.

philote

MIS
Oct 2, 2003
861
US
I'm using the dib mod to connect to a mysql database to insert records. One column is a primary key that gets auto_updated. I want to know how I can get this primary key when I run the sql statement to insert the record. I noticed the
Code:
db-handle->do
returns the number of records affected but I didn't know if any of the other functions would actually return the key or if there's an SQL command that would retrieve it for me.

Kevin
A+, Network+, MCP
 
Well I guess I didn't research enough before posting. Looks like I need to use the DBI method "last_insert_id" immediately after inserting my row.

Kevin
A+, Network+, MCP
 
Or, write a database stored procedure that does the insert and returns the PK. Can you do stored procedures with MySQL??? I don't remember....maybe in later versions???? If you can, the procedure will eliminate the possibility of two nearly simultaneous submissions getting confused.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Great idea! I'll have to check into MySQL and shared procedures. I think it's possible but I've never done it before.

Kevin
A+, Network+, MCP
 
Well, it looks possible but too complicated for me right now.

Also I just found out that the method I was using only gives the last auto_incremented id for your particular session, so that may help avoid problems.

Kevin
A+, Network+, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top