Converting MYSQL Saving Codes into .INI Saving System codes ???? -
PURG3D - 14.04.2015
Guys if we cannot solve this. My problem :
https://sampforum.blast.hk/showthread.php?tid=570342
Lets just skip that, and Proceed to my next problem.
Heres my problem. Is there any way to convert these mysql saving and loading saving into .ini saving and loading system? like fwrite ? fload ?
MYSQL Save
pawn Code:
stock g_mysql_SaveMOTD()
{
new query[1024];
format(query, sizeof(query), "UPDATE `misc` SET ");
format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
format(query, sizeof(query), "%s `aMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
format(query, sizeof(query), "%s `vMOTD` = '%s',", query, g_mysql_ReturnEscaped(VIPMOTD, MainPipeline));
format(query, sizeof(query), "%s `cMOTD` = '%s',", query, g_mysql_ReturnEscaped(CAMOTD, MainPipeline));
format(query, sizeof(query), "%s `pMOTD` = '%s',", query, g_mysql_ReturnEscaped(pMOTD, MainPipeline));
format(query, sizeof(query), "%s `ShopTechPay` = '%.2f',", query, ShopTechPay);
format(query, sizeof(query), "%s `GiftCode` = '%s',", query, g_mysql_ReturnEscaped(GiftCode, MainPipeline));
format(query, sizeof(query), "%s `GiftCodeBypass` = '%d',", query, GiftCodeBypass);
format(query, sizeof(query), "%s `TotalCitizens` = '%d',", query, TotalCitizens);
format(query, sizeof(query), "%s `TRCitizens` = '%d',", query, TRCitizens);
format(query, sizeof(query), "%s `ShopClosed` = '%d',", query, ShopClosed);
format(query, sizeof(query), "%s `RimMod` = '%d',", query, RimMod);
format(query, sizeof(query), "%s `CarVoucher` = '%d',", query, CarVoucher);
format(query, sizeof(query), "%s `PVIPVoucher` = '%d',", query, PVIPVoucher);
format(query, sizeof(query), "%s `GarageVW` = '%d',", query, GarageVW);
format(query, sizeof(query), "%s `PumpkinStock` = '%d',", query, PumpkinStock);
format(query, sizeof(query), "%s `HalloweenShop` = '%d'", query, HalloweenShop);
mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}
MYSQL Load
pawn Code:
stock g_mysql_LoadMOTD()
{
mysql_function_query(MainPipeline, "SELECT `gMOTD`,`aMOTD`,`vMOTD`,`cMOTD`,`pMOTD`,`ShopTechPay`,`GiftCode`,`GiftCodeBypass`,`TotalCitizens`,`TRCitizens`,`SecurityCode`,`ShopClosed`,`RimMod`,`CarVoucher`,`PVIPVoucher`, `GarageVW`, `PumpkinStock`, `HalloweenShop` FROM `misc`", true, "OnQueryFinish", "iii", LOADMOTDDATA_THREAD, INVALID_PLAYER_ID, -1);
}
Is there any way to convert those codes above into .ini saving? For easy understand, Like saving and loading them all into .ini file inside the scriptfiles folder.
I know this is the hardest thing to code, I apologizes for those getting hardcore. I promise i will give ++REP on those who can help me out.
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
PURG3D - 14.04.2015
anyone?
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
iiNzTicTx - 14.04.2015
Why would you prefer ini over sql? If it was me I'd personally keep using mysql...
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
EiresJason - 14.04.2015
Did you look at my reply to your other thread or do you just want to leave it and go ahead with this? sd
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
PURG3D - 14.04.2015
Quote:
Originally Posted by EiresJason
Did you look at my reply to your other thread or do you just want to leave it and go ahead with this?
|
I do.
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
PURG3D - 14.04.2015
Quote:
Originally Posted by iiNzTicTx
Why would you prefer ini over sql? If it was me I'd personally keep using mysql...
|
Because MYSQL is hardcore coding for me. And i think theres no else solution that can solve my problem in my previous thread.
Re: Converting MYSQL Saving Codes into .INI Saving System codes ???? -
iiNzTicTx - 14.04.2015
Quote:
Originally Posted by PURG3D
Because MYSQL is hardcore coding for me. And i think theres no else solution that can solve my problem in my previous thread.
|
It's easier than dini. Just look at examples of loading/saving functions such as a registration system. Just a waste of time and effort converting back to a disadvantaged method.
Basically when the gamemode connects you want to connect to the mySQL using the function: mysql_connect().
On register you want to create a new row, all the values you really should need to put in are the important values: name, password ect. You will want to use mysql_format() for this to INSERT. Reminder! For all user input strings you want to use '%e' instead of '%s', this will escape the string. If you don't you are vulnerable to injections. After that: mysql_tquery. Same applies to saving data!!
On login you want to SELECT from mySQL. You want to loop through each row in mySQL using cache_get_row_count(),
for(new i = 0; i < cache_get_row_count(); i++)
{
... load row inside here.
}
When loading data it's important that you fetch the player name from that row, match it, then check that the input password is the same! NOTE: encrypt the password the user inputs, and check it with an already encrypted password saved to mySQL.
When saving, you want to update a mySQL row. Below is an example,
mysql_format(connection_handle, string, sizeof(string), "UPDATE `tablename` SET `Money` = %d`WHERE `name`='%e'", player_money, player_name);
mysql_tquery(mysql_tquery(connection_handle, string, "", "");
connection_handle is the variable that stores the mysql connection: connection_handle = mysql_connect(...)
Do some research buddy. I have provided an example in a different context, the concept remains the same!