SA-MP Forums Archive
MySQL problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL problem (/showthread.php?tid=574761)



MySQL problem - MikE1990 - 20.05.2015

Hello i have problem with mysql i use the newest version and when i load my houses i get this in mysql log

Код:
[18:26:58] [DEBUG] cache_get_field_content_int - row: 0, field_name: "ID", connection: 1
[18:26:58] [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0')



Re: MySQL problem - Vince - 20.05.2015

You don't have a resultset. This is in a callback, I hope?


Re: MySQL problem - MikE1990 - 20.05.2015

This is the code
Код:
LoadHouses()
{
	for(new i = 0;i < MAX_HOUSES;i++)
	{
		new query[50];
		mysql_format(connection,query,sizeof(query),"SELECT * FROM Houses WHERE ID = '%i'",i);
		mysql_tquery(connection,query,"LoadHousesData","i",i);
		CreateHouse(i,HouseInfo[i][X],HouseInfo[i][Y],HouseInfo[i][Z],HouseInfo[i][Owner]);
	}
}

forward LoadHousesData(houseID);
public LoadHousesData(houseID)
{
	HouseInfo[houseID][ID] = cache_get_field_content_int(0,"ID");
	HouseInfo[houseID][X] = cache_get_field_content_int(0,"X"); 
	HouseInfo[houseID][Y] = cache_get_field_content_int(0,"Y");
	HouseInfo[houseID][Z] = cache_get_field_content_int(0,"Z");
	HouseInfo[houseID][Price] = cache_get_field_content_int(0,"Price");
	HouseInfo[houseID][Interior] = cache_get_field_content_int(0,"Interior");
	HouseInfo[houseID][Owned] = cache_get_field_content_int(0,"Owned");
	cache_get_field_content(0,"Owner",HouseInfo[houseID][Owner],connection,20);
	HouseInfo[houseID][VehicleSlot1] = cache_get_field_content_int(0,"VehicleSlot1");
	HouseInfo[houseID][VehicleSlot2] = cache_get_field_content_int(0,"VehicleSlot2");
	HouseInfo[houseID][VehicleSlot3] = cache_get_field_content_int(0,"VehicleSlot3");
	return 1;
}



Re: MySQL problem - Vince - 20.05.2015

Oh, that's horrible. Never load rows one by one if not absolutely necessary since it puts extra stress on the system. MySQL is powerful tool, but you should know how to work it.

PHP код:
mysql_tquery(connection,"SELECT * FROM houses LIMIT " #MAX_HOUSES, "LoadHousesData"); 
PHP код:
public LoadHousesData()
{
    for(new 
0cache_get_row_count(); ji++)
    {
        
HouseInfo[i][ID] = cache_get_field_content_int(i,"ID");
        
// etc
        
CreateHouse(i,HouseInfo[i][X],HouseInfo[i][Y],HouseInfo[i][Z],HouseInfo[i][Owner]);
    }

Also try not to store a player's name (or any data for that matter) more than once in the entire database. If you need the player's name you need to join the player table. If a player's name were to change you would have to change it in all places it is used, whereas with proper normalization it would only need to be changed in one place.


Re: MySQL problem - MikE1990 - 20.05.2015

Aha i got it now,it works.Thank you rep++