SA-MP Forums Archive
last_insert_id and mysql_insert_id - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: last_insert_id and mysql_insert_id (/showthread.php?tid=458564)



last_insert_id and mysql_insert_id - Zex Tan - 17.08.2013

Title says it all, but what's the difference between last_insert_id and mysql_insert_id? As far as I know, is last_insert_id updates the ID and stuff Or is it the same as mysql_insert_id. I've tried mysql_insert_id once, but when I deleted a column it doesn't update the IDs when it was like 1,2,3,4 and deleted 2. But it continues with 5. I've searched about it but can't really understand it well... Need some explanation please ^_^


Re: last_insert_id and mysql_insert_id - Misiur - 17.08.2013

You should not reuse primary key indexes when deleting elements. It won't update anything, only return the ID of last element inserted ( http://dev.mysql.com/doc/refman/5.0/...last-insert-id mroe info)


Re: last_insert_id and mysql_insert_id - Zex Tan - 17.08.2013

So what about an example of BanID? When there's 1, 2, 3, 4 and I unban ID 2 and when I ban a player, that player will get BanID 2. How can I do that?


Re: last_insert_id and mysql_insert_id - Misiur - 17.08.2013

1. Add field to users table, called banID, with NULL allowed values
2. Create table bans
3. Create relation between banID in users table, with id in bans table
4. Store all bans history in bans table, but keep only most recent in banID field for specific user (or NULL if user isn't banned)
5. You can also add userID field in bans table, with relation to users.id field, so your bans history track can be more useful