我想获得最后插入的行的ID,我使用mysql_insert_id()函数。但给人的问题php mysql获取最后一个插入行的ID给出错
这里是我的代码:
if($i == 0)
{
$query = "update events set e_did ='".$multi_event."' where eid = '".$display_id."'";
mysqli_query($con,$query);
file_put_contents('log.txt', mysql_insert_id(), FILE_APPEND);
}
else
{
$query = "INSERT INTO events (start_date, end_date, text, rec_type, event_pid, event_length, e_did) VALUES ('".$row['start_date']."','".$row['end_date']."','".$row['text']."','".$row['rec_type']."','".$row['event_pid']."','".$row['event_length']."','".$multi_event."')";
mysqli_query($con,$query);
file_put_contents('log.txt', 'A'.mysql_insert_id().'A', FILE_APPEND);
}
现在无论时间I M得到相同的ID。什么是问题。我在某处做错了什么?
你有任何主键自动增加你的表'事件'? –
id列自动递增 –
所以它应该在插入查询后工作.it将不会在更新后查询 –