cache_insert_id Problem. (BlueG's plugin) -
rappy93 - 22.05.2014
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:05] INSERT INTO `furnitures` (model, name, houseid, interior, virworld, marketprice, posx, posy, posz) VALUES (1369, 'Wheelchair', 169, 10, 149, 500, 388.019226, 1506.852173, 1080.092529)
[15:24:05] Furniture inserted with ID : 0
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.
Re: cache_insert_id Problem. (BlueG's plugin) -
Konstantinos - 22.05.2014
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]);
}
Re: cache_insert_id Problem. (BlueG's plugin) -
rappy93 - 22.05.2014
Okay,I'm compiling it now and testing.
I'll be back with an edit afterwards.
Re: cache_insert_id Problem. (BlueG's plugin) -
MacT - 22.05.2014
Kontantinos, can you check my MySQL privately ?
Re: cache_insert_id Problem. (BlueG's plugin) -
rappy93 - 22.05.2014
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
Re: cache_insert_id Problem. (BlueG's plugin) -
MacT - 22.05.2014
Haha nice work, partner. Yea I am too slow, damn old man