cache_insert_id return 0 :x
#1

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?
Reply
#2

Use Cache_insert_id() into callback that call with mysql_tquery
Reply
#3

If you have more of two connections use cache_insert_id(connectionname), and use threads
Reply
#4

new debug = cache_insert_id(MySQLConnect);
printf("Id %d inserted in database", debug);

Works?
Reply
#5

debug = 1, but id in database = 4
Reply
#6

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;
}
Reply
#7

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
Reply
#8

uppp
Reply
#9

You need to use 'mysql_query' for the function 'cache_insert_id' in the same code.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)