例如数据库有以下字段
id 自增字段,int型
linename 字符型
price 数值型如果执行了代码:
<?php
$sql="insert into line set linename='".$name."',price=".$price;
$db->query($sql);
?>如何才能得到刚刚添加的这条记录的id字段的值?谢谢各位.

解决方案 »

  1.   


    $sql="select max(id) from line";
    $rs=mysql_query($sql);
    $rw=mysql_fetch_row($rs);
    echo $rw[0];
      

  2.   

    return @mysql_insert_id($this->connect_id);  $this->connect_id 为你建立的mysql 链接返回的链接句柄
      

  3.   

    如果是OO的话 就应该是下面这样:
    $db=new mysqli('localhost','root','','test');
    $result=$db->query("INSERT INTO  test(id) VALUES('a')");
    print $db->insert_id;