Php 插入到表中时如何获取ID
我在表中插入值,但我想在插入时获取列的idPhp 插入到表中时如何获取ID,php,mysql,sql,insert-into,Php,Mysql,Sql,Insert Into,我在表中插入值,但我想在插入时获取列的id 这是我的代码 $addInsurance = mysql_query("INSERT INTO insurance (coo_Country,pod_Country,startDate,finishDate,insGNumber,insKNumber,customer_customer_ID) VALUES ('$cikiscity','$variscity','$baslangicTarih','$bitisTarih','$yetiskin','$
这是我的代码
$addInsurance = mysql_query("INSERT INTO insurance (coo_Country,pod_Country,startDate,finishDate,insGNumber,insKNumber,customer_customer_ID) VALUES ('$cikiscity','$variscity','$baslangicTarih','$bitisTarih','$yetiskin','$cocuk','$customer_id') SET '$ID'=insurance_ID");
if (!$addInsurance) {
echo'Could not run query' . mysql_error($connection);
}
我想在保险表中获得保险ID我该怎么做?在您的else声明中这样做:
else {
echo mysql_insert_id();
}
虽然我不推荐它,因为MySQL扩展在较新版本的PHP中已被弃用。通常,要向MySQL程序员发出查询,请使用或PHP的扩展。如果可以的话,尝试使用MySQLi。它的等价物是mysqli_insert_id()函数。您可能在寻找
UPDATE
语句吗?@mario,我猜OP是在寻找LAST_insert_id()