cache_insert_id Problem. (BlueG's plugin)
#1

Hey. So basically my problem is that whenever I insert something in the database it returns ID 0 until I restart the server. Look here :

pawn Код:
mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `furnitures` (model, name, houseid, interior, virworld, marketprice, posx, posy, posz) VALUES (%d, '%s', %d, %d, %d, %d, %f, %f, %f)",
model, name, HouseInfo[houseid][hID], interior, world, price, x, y ,z);

mysql_tquery(dbHandle, query);
printf("Furniture inserted with ID : %d", cache_insert_id());
This is the log.
PHP код:
[15:24:05INSERT INTO `furnitures` (modelnamehouseidinteriorvirworldmarketpriceposxposyposzVALUES (1369'Wheelchair'16910149500388.0192261506.8521731080.092529)
[
15:24:05Furniture inserted with ID 
Any ideas why it keeps returning 0 instead of the actual ID ? The table has auto_increment.

I also tried with cache_insert_id(dbHandle), same result.
Reply
#2

I don't think you can call that function outside of the callback you use in the mysql_(t/p)query function.
As you're sure that there is auto-increment for that field:
pawn Код:
mysql_format(dbHandle, query, sizeof(query), "INSERT INTO `furnitures` (model, name, houseid, interior, virworld, marketprice, posx, posy, posz) VALUES (%d, '%s', %d, %d, %d, %d, %f, %f, %f)",
model, name, HouseInfo[houseid][hID], interior, world, price, x, y ,z);
mysql_tquery(dbHandle, query, "OnFurnitureInsert", "i", houseid);
pawn Код:
forward OnFurnitureInsert(house_ID);
public OnFurnitureInsert(house_ID)
{
    printf("Furniture inserted with ID \"%i\" for houseid \"%i\"", cache_insert_id(), HouseInfo[house_ID][hID]);
}
Reply
#3

Okay,I'm compiling it now and testing.
I'll be back with an edit afterwards.
Reply
#4

Kontantinos, can you check my MySQL privately ?
Reply
#5

Well,that worked.Thank's Konstantions. I don't know what everyone here would do without you !

I'd +rep you if I could do it again
Reply
#6

Haha nice work, partner. Yea I am too slow, damn old man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)