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?