Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 插入到表中时如何获取ID_Php_Mysql_Sql_Insert Into - Fatal编程技术网

Php 插入到表中时如何获取ID

Php 插入到表中时如何获取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','$

我在表中插入值,但我想在插入时获取列的id
这是我的代码

$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()