is mysql_insert_id safe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    is mysql_insert_id safe

    Hi all

    With regard to mysql's mysql_insert_id function is it possible that the
    query can return the insert id from another insert performed by a
    another user of the database which occured after the initial insert by
    the first user but b4 the insert_id part can be queried.


    Regards

    Marc

  • Rik

    #2
    Re: is mysql_insert_id safe

    monomaniac21 wrote:[color=blue]
    > Hi all
    >
    > With regard to mysql's mysql_insert_id function is it possible that
    > the query can return the insert id from another insert performed by a
    > another user of the database which occured after the initial insert by
    > the first user but b4 the insert_id part can be queried.[/color]

    No, mysql_insert_id () in the same script always gets the value of the last
    query performed by that specific script, not by other connections to the
    database.

    Grtz,
    --
    Rik Wasmus


    Comment

    • Karl Groves

      #3
      Re: is mysql_insert_id safe

      "monomaniac 21" <mcyi2mr3@googl email.com> wrote in
      news:1150196939 .699842.166890@ f6g2000cwb.goog legroups.com:
      [color=blue]
      > Hi all
      >
      > With regard to mysql's mysql_insert_id function is it possible that the
      > query can return the insert id from another insert performed by a
      > another user of the database which occured after the initial insert by
      > the first user but b4 the insert_id part can be queried.
      >[/color]

      You won't have any problems if you're running it immediately after the
      query.



      --
      Karl Groves

      Comment

      • Gordon Burditt

        #4
        Re: is mysql_insert_id safe

        >> With regard to mysql's mysql_insert_id function is it possible that the[color=blue][color=green]
        >> query can return the insert id from another insert performed by a
        >> another user of the database which occured after the initial insert by
        >> the first user but b4 the insert_id part can be queried.
        >>[/color]
        >
        >You won't have any problems if you're running it immediately after the
        >query.[/color]

        In the database world, there is no "immediatel y after". It's always
        possible for someone else to get in a query between any two of
        yours. It's up to locking (implicit or explicit) or transactions
        to prevent bad effects on the data from this by delaying execution
        of one until another finishes.

        mysql_insert_id () returns the last insert id ON THIS CONNECTION.
        So, as long as you keep the connection open (which probably won't
        be beyond the processing of the PHP page: with persistent connections,
        you are NOT guaranteed to get the same connection next time), you
        can wait as long as you want to call mysql_insert_id ().

        Gordon L. Burditt

        Comment

        Working...