如题

解决方案 »

  1.   

    last_insert_id()mysql> create table t1 (id int not null auto_increment ,name varchar(10),primary key (id));
    Query OK, 0 rows affected (0.00 sec)
    inser t1 (name) values ('aaa');
    inser t1 (name) values ('bbb');
    inser t1 (name) values ('ccc');
    inser t1 (name) values ('ddd');
    mysql> select * from t1;
    +----+------+
    | id | name |
    +----+------+
    |  1 | aaa  | 
    |  2 | bbb  | 
    |  3 | ccc  | 
    |  4 | ddd  | 
    +----+------+
    4 rows in set (0.00 sec)mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                4 | 
    +------------------+
    1 row in set (0.00 sec)
      

  2.   

    如果用自增字段,用last_insert_id()