[thelist] Sessions in PHP4

Anthony Baratta Anthony at Baratta.com
Tue Jul 25 19:10:38 CDT 2000


rudy limeback wrote:
> 
> and anthony (i think it was you, anyway), what was the comparable technique
> in sql/server -- @@identity or something? could you please refresh my
> memory and summarize how this works?  is it an asp only thing, or do i need
> a stored procedure?

Simon is the guru of the @@identity, I'm not worthy to stand in his shadow. ;-)

But here is what I do know:

The @@identity is specific to your connection. That means that if someone else
inserts into the DB before you grab the @@identity, it should not affect the number
you retrieve.

Here's example :

'' Database Connection String
 DB_Connect_String = "Data Source=Blah-DB;UID=Blah_User;Pwd=Blah_Password;"

'' ODBC Connection Schtuff
 Set objDB_Connection = Server.CreateObject("ADODB.Connection")
     objDB_Connection.Open DB_Connect_String
 Set objDB_RecordSet = Server.CreateObject("ADODB.Recordset")       
 Set objDB_RecordSet.ActiveConnection = objDB_Connection

'' Insert into Database
 strQuery = "INSERT INTO Blah_Table Values('" & varBlah1 & "',"
 strQuery = strQuery & "'" & EscapeDBData(varBlah3) & "','"
 strQuery = strQuery & "'" & EscapeDBData(varBlah2) & "')"
 objDB_Connection.Execute strQuery

'' Getting Identity 
 objDB_RecordSet.Open "Select @@Identity as varID"
 varOrderKey = objDB_RecordSet("varID")
 objDB_RecordSet.Close

'' EscapeDBData to make sure user provided data may have ', and are escaped
 Function EscapeDBData(varDataLine)
    varDataLine = Replace(varDataLine,"'","''",1,-1,1)
    EscapeDBData = varDataLine
 End Function

-- 
Anthony Baratta
President
KeyBoard Jockeys
                    South Park Speaks Version 3 is here!!!
                       http://www.baratta.com/southpark
                              Powered by Tsunami




More information about the thelist mailing list