MySQL last_insert_id()

Results 1 to 2 of 2

Thread: MySQL last_insert_id()

  1. #1
    Join Date
    Dec 1969

    Default MySQL last_insert_id()

    I&#039;m having a problem getting the autoincrement value from an insert using mysql. I have written a short script highlighting my problem:<BR><BR>-----------<BR>Set Conn = Server.CreateObject("ADODB.Connection")<BR>Set RS = Server.CreateObject("ADODB.RecordSet")<BR>Conn.Ope n "Driver={MySQL};Option=131072;Database=mydb;Uid=my user;Pwd=mypass;"<BR>Conn.Execute "insert into templates (templatename) values (&#039;test&#039;)"<BR>Conn.Execute "insert into templates (templatename) values (last_insert_id())"<BR>RS.Open "Select last_insert_id() as thisid", Conn<BR>Response.Write RS.EOF<BR>RS.Close<BR>Conn.Close<BR>Set RS = Nothing<BR>Set Conn = Nothing<BR>-----------<BR><BR>The first insert works fine, as does the second (using the correct value from the first) but when i try to pull out the value into a recordset i get a recordset with no rows, i.e. RS.EOF is true.<BR><BR>Am I going about this correctly? Any help would be appreciated.

  2. #2
    Join Date
    Dec 1969

    Default MySQL doesn't support...

    ...using SELECT to get anything but the results of a table-based query. You are trying to use it like a stored proc SELECT.<BR><BR>You *might* look here:<BR><BR><BR>Look especially at the last 3 lines of that piece of docs.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts