SA-MP Forums Archive
Possible to find which ID was created MySQL INSERT? - 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: Possible to find which ID was created MySQL INSERT? (/showthread.php?tid=496364)



Possible to find which ID was created MySQL INSERT? - Ryan_Undering - 21.02.2014

Okay, so what I'm trying to do, for arguments sake is:

When a vehicle is INSERTED into the 'vehicles' table, retrieve the ID from the inserted row to save to a variable?

pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][vAngle], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");

Also, if someone who has knowledge in this area of scripting could PM me with their skype name, it'd be rather handy as I have a few more questions just to verify my methods and whether they can be done easier... As it doesn't seem fit for me to create new threads each time I have a question! Haha.


Re: Possible to find which ID was created MySQL INSERT? - Vince - 21.02.2014

Does the table contain an auto_increment field? If so, create a callback and call cache_insert_id() or mysql_insert_id().


Re: Possible to find which ID was created MySQL INSERT? - Ryan_Undering - 21.02.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Does the table contain an auto_increment field? If so, create a callback and call cache_insert_id() or mysql_insert_id().
Again.. simple.. I'd used it before and forgot about it... Thanks :l... Gave you some rep.


Re: Possible to find which ID was created MySQL INSERT? - Roam - 21.02.2014

pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][Ale], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");
And this?


Re: Possible to find which ID was created MySQL INSERT? - Ryan_Undering - 21.02.2014

Quote:
Originally Posted by Roam
Посмотреть сообщение
pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][Ale], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");
And this?
What do you mean?