cache_insert_id return 0 :x -
Baltimore - 31.12.2014
Hello !
I use MySQL R39-2.
My cache_insert_id return 0.
pawn Код:
mysql_format(MySQLConnect, query, 1024, "INSERT INTO `vehs` (`ModelID`, `PosX`, `PosY`, `PosZ`, `PosA`, `Couleur1`, `Couleur2`) VALUES (%d, '%f', '%f', '%f', '%f', %d, %d)", VehInfo[entry][ModelID], VehInfo[entry][Pos][0], VehInfo[entry][Pos][1], VehInfo[entry][Pos][2], VehInfo[entry][Pos][3], couleur1, couleur2);
mysql_tquery(MySQLConnect, query);
printf("%d", cache_insert_id());
Return 0 :/
Can u help me?
Re: cache_insert_id return 0 :x -
M4D - 31.12.2014
Use Cache_insert_id() into callback that call with mysql_tquery
Respuesta: cache_insert_id return 0 :x -
Zume - 31.12.2014
If you have more of two connections use cache_insert_id(connectionname), and use threads
Re: cache_insert_id return 0 :x -
AdmBot - 31.12.2014
new debug = cache_insert_id(MySQLConnect);
printf("Id %d inserted in database", debug);
Works?
Re : cache_insert_id return 0 :x -
Baltimore - 31.12.2014
debug = 1, but id in database = 4
Re: cache_insert_id return 0 :x -
Lordzy - 31.12.2014
It is a threaded query, so you've to mention the callback where it stores data of the query which was sent.
pawn Код:
mysql_tquery(connectionHandle, "INSERT INTO...", "OnVehicleInsert", "i", entry); //You don't have to fill up entry if not needed.
forward OnVehicleInsert(entry_id);
public OnVehicleInsert(entry_id)
{
printf("insert id : %d", cache_insert_id(connectionHandle));
return 1;
}
Re : cache_insert_id return 0 :x -
Baltimore - 31.12.2014
Hello !
I have 3 vehicles for exemple, and cache_insert_id it's good
But, if i restart my serveur.. cache_insert_id() = 1 not 4
Re : cache_insert_id return 0 :x -
Baltimore - 31.12.2014
uppp
Re : cache_insert_id return 0 :x -
Dark_Rider29 - 01.01.2015
You need to use 'mysql_query' for the function 'cache_insert_id' in the same code.
Re: cache_insert_id return 0 :x -
Sawalha - 01.01.2015
pawn Код:
mysql_format(MySQLConnect, query, 1024, "INSERT INTO `vehs` (`ModelID`, `PosX`, `PosY`, `PosZ`, `PosA`, `Couleur1`, `Couleur2`) VALUES (%d, '%f', '%f', '%f', '%f', %d, %d)", VehInfo[entry][ModelID], VehInfo[entry][Pos][0], VehInfo[entry][Pos][1], VehInfo[entry][Pos][2], VehInfo[entry][Pos][3], couleur1, couleur2);
mysql_tquery(MySQLConnect, query, "OnVehicleCreated", "i", entry);
for your VehInfo array, add "VID" , vehicle id which we are gonna store in the mysql database.
now on The "OnVehicleCreated" Callback part:
pawn Код:
forward OnVehicleCreated(entry);
public OnVehicleCreated(entry)
{
VehInfo[entry][VID] = cache_insert_id(); // here, we set the vehicle id in this variable, and the mysql VID field, which we're gonna add later.
printf("%i", VehInfo[entry][VID]); // debugging.
}
Now, the mysql part.
After launching your XAMP program to start the localhost to access the mysql database, go to vehicles table,
and Add a new field called "VID" , In index, (while you are creating it) , put "PRIMARY", and enable "A_I", that's required for a UID in every MySQL table.
an example in this tut:
https://sampforum.blast.hk/showthread.php?tid=485633 , look at the 8th picture.
now you are done, check mysql_log.txt for any notices / errors returned.