I'm using MySQL with php's pear interface and I am trying to find out the id of the item I last inserted.

mysql has lastinsertid().. or something like that, but i'm not sure how to do it through pear.

any ideas?

    I was informed that this query would work:
    "select last_insert_id()"

    i've tried:
    $query = "select last_insert_id() as ds from gallery_pho";
    $query = "select last_insert_id() as ds";
    $query = "select last_insert_id()";

    and they only give me '0' as a result... am I using this right?

      If your id numbers are automatically incremented you can get the last id this way

      $result = mysql_query("select MAX(Id) as maxnum FROM table",$db); 

        If your id numbers are automatically incremented you can get the last id this way

        Nope. The max id in the table is not necessarily the same as the id you just inserted. Web servers are multi-threaded, so another insert could've occured before the max function is called. That would give you the wrong number.

          Write a Reply...