Search code examples
phpsqlformswebupdating

Retrieving Created for Primary for edit


On my web app people can create create what I call a case. On the back end side when they submit it saves it into a MSSQL DB table. After they hit save it'll create the new entry in the DB, what I need is to be able to retrieve the Idenity row (auto increment) which is my primary key so that I can save it in the session (PHP) for if the user hits save (to update) again.

My question, I know this is a common practice, what is the common way of doing so I was thinking about using SQL SCOPE_IDENTITY but was reading about common bugs here:

http://blog.sqlauthority.com/2009/03/24/sql-server-2008-scope_identity-bug-with-multi-processor-parallel-plan-and-solution/

Thanks in advance


Solution

  • If I understand your question correctly. I think this'll help.

    http://php.net/manual/en/function.mysql-insert-id.php