mysql_insert_id() => 返回最后插入的记录ID

解决方案 »

  1.   

    主键是自动增长的数值?
    调用函数 mysql_insert_id()
    22.2.3.36. mysql_insert_id()
    my_ulonglong mysql_insert_id(MYSQL *mysql) Description Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Use this function after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field. 
      

  2.   

    能具体一点吗?比如A表的话,如何用这个方法获得它的主键呢,能给个SQL语句吗??谢谢了
      

  3.   

    没看到吗?
    Use this function after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field.
    mysql_query(mysql, "INSERT INTO A VALUES(...)");
    就可以调用mysql_insert_id(mysql)了。