php - Last insert id issue--How to fetch it -
I enter $ id = mysqli_insert_id ($ connection) to enter the previous code; I'm using
, but if it updates any record in the table, it returns 0
as the last inserted id.
Is there any way to handle this?
I have to get the ID every time to insert or update the weather.
Thanks
Edit
I need this ID to use in the data table2
insert data from
to enter data from ID1 tab2
to ID tab 1 < / Code> is
FK
And most importantly, I am not using with
update
, where section
This is my code
that I am using
$ val = utf8_encode ($ val); Mysqli_set_charset ($ connection, 'utf8'); MySqli_query ($ connection, "SET NAMES 'utf8'); Mysqli_query ($ connection," SET FOREIGN_KEY_CHECKS = 0; "); $ Sql =" Enter in the leak ($ inserted) value ($ val) "; $ Sql = "Key Update of Duplicate 'URL` ='" .mysqli_real_escape_string ($ connection, $ data ['url']). ''; '; Mysqli_query ($ connection, ($ sql)) or die (mysqli_error ($ connection). "& Lt; br />".print($sql)); $ Id = mysqli_insert_id ($ connection); $ Proof ['leaks_id'] = $ id; Mysqli_query ($ connection, "SET FOREIGN_KEY_CHECKS = 0;"); Print_r ($ id); $ This- & gt; InsertProofs ($ connection, $ proof); Connection :: close_connection ($ connection);
Please note that >> on For example, if your You can then run . I see that you are using a duplicate key update on You can modify your query (assuming that the for example, id = LAST_INSERT_ID (id) If I run (if we exist with the record of Output $ this-> InsertProofs ($ connection, $ proof);
insert
data near table2
near key
on
INSERT
UPDATE
depending on your updates;
id
will know if you are updating ID
to search for updates . UPDATE
was something like this; UPDATE `foo` SET`x` = 'y' where 'a` =' b '
Edit
.
id
is the primary auto_interpret key)
on the duplicate key update `url `= '" .mysqli_real_escape_string ($ connection, $ data [' url ']).' For example, if you have
UPDATE
or INSERT
id = 2
; so we have update
);
FuBar (id, foo) Update the duplicate key in VALUES (2, 'bar'), INSERT at foo = 'baz'. Id = LAST_INSERT_ID (id); SELECT LAST_INSERT_ID ();
2, because it was the last insert id.
Comments
Post a Comment