Help really needed :( -
P<3TS - 10.08.2012
Hello.
My server is having more that +10000 user accounts in volt host.Now the server is lagging like hell, i asked about this in volt support they told me i have to convert the script to MySQL cuz pawno cannot hold a large amount of user accounts and thats the main cause of lag.
I'm currently using ladmin system, i know how to script pawno but no idea about MySQL. I searched tutorials but i didnt understand anything. I really want to convert my script to MySQL otherwise i have to close my server forever.
Can anyone please tell me how can i convert my script to MySQL?
Register command
pawn Код:
CMD:register(playerid,params[]){
if (PlayerInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid,COLOR_RED,"ACCOUNT: You are already registered and logged in.");
if (udb_Exists(PlayerName2(playerid))) return SendClientMessage(playerid,COLOR_RED,"ACCOUNT: This account already exists, please use '/login [password]'.");
if (strlen(params) == 0) return SendClientMessage(playerid,COLOR_RED,"ACCOUNT: Correct usage: '/register [password]'");
if (strlen(params) < 4 || strlen(params) > 20) return SendClientMessage(playerid,COLOR_RED,"ACCOUNT: Password length must be greater than three characters");
if (udb_Create(PlayerName2(playerid),params)){
new file[256],rname[MAX_PLAYER_NAME], tmp3[100];
new strdate[20], year,month,day;
getdate(year, month, day);
GetPlayerName(playerid,rname,sizeof(rname));
format(file,sizeof(file),"/ladmin/users/%s.sav",udb_encode(rname));
GetPlayerIp(playerid,tmp3,100);
dini_Set(file,"ip",tmp3);
dUserSetINT(PlayerName2(playerid)).("registered",1);
format(strdate, sizeof(strdate), "%d/%d/%d",day,month,year);
dini_Set(file,"RegisteredDate",strdate);
dUserSetINT(PlayerName2(playerid)).("loggedin",1);
dUserSetINT(PlayerName2(playerid)).("banned",0);
dUserSetINT(PlayerName2(playerid)).("level",0);
dUserSetINT(PlayerName2(playerid)).("LastOn",0);
dUserSetINT(PlayerName2(playerid)).("money",0);
dUserSetINT(PlayerName2(playerid)).("kills",0);
dUserSetINT(PlayerName2(playerid)).("deaths",0);
dUserSetINT(PlayerName2(playerid)).("Bank",PlayerInfo[playerid][bank]);
dUserSetINT(PlayerName2(playerid)).("weed",PlayerInfo[playerid][weed]);
dUserSetINT(PlayerName2(playerid)).("Condoms",PlayerInfo[playerid][condoms]);
dUserSetINT(PlayerName2(playerid)).("inalcatraz",PlayerInfo[playerid][inalcatraz]);
PlayerInfo[playerid][LoggedIn] = 1;
PlayerInfo[playerid][Registered] = 1;
SavePlayer(playerid);
LoginPlayer(playerid);
LoadPlayer(playerid);
Re: Help really needed :( -
Danijel. - 10.08.2012
As far as i know,writing/reading in files has always been faster than SQL.
Re: Help really needed :( -
Ranama - 11.08.2012
Quote:
Originally Posted by Danijel.
As far as i know,writing/reading in files has always been faster than SQL.
|
You but that don't mean that they is taking less memory on your harddrive,
Edit after reading FalconX post: i think this what i said might be wrong, the memory usage may be the same but it'll be faster searching mysql
and bout the maint topic, try search ****** for basic tutorials and try to understand the tutorials on this forum becuse once you do you'll understand how to use it and it'll become pretty easy.(another option is that you pay someone to convert it for you I've see a-lot op peoples having int their signatures like(converting ini to mysql for cash) etc.)
Re: Help really needed :( -
FalconX - 11.08.2012
Quote:
Originally Posted by Danijel.
As far as i know,writing/reading in files has always been faster than SQL.
|
Hmm, well if you have more then 10k users in your server and you want to loop them to check how many users are registered it will take such a long time to read each and every file for checking, I use MySQL and recommend people to use. Everyone thinks their own way - different people different thoughts.
https://sampwiki.blast.hk/wiki/Mysql_tutorial
I believe this will help you in learning MySQL. Following is hOw you can make a framework or connection setup, put the following at top:-
pawn Код:
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
And now put "ConnectMySQL( );" in OnGamemodeInit and the following can be put anywhere you want.
pawn Код:
forward ConnectMySQL();
public ConnectMySQL()
{
mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
*
if(mysql_ping() == 1)
{
mysql_debug(1);
printf("[MYSQL]: Connection to `%s` succesful!", SQL_DB);
}
else
{
printf("[MYSQL]: [ERROR]: Connection to `%s` failed!", SQL_DB);
}
return 1;
}
Now for queries you can get help from Tizag.com it is a very helpful site.
Re: Help really needed :( -
P<3TS - 11.08.2012
What is the difference between SQL and MySQL?
Re: Help really needed :( -
FalconX - 11.08.2012
Quote:
Originally Posted by P<3TS
What is the difference between SQL and MySQL?
|
SQlite does not require a server to be set up, it is usually used with an application to allow data to be stored, this might be a contact list etc. It can only be used locally (i think).
MySQL is designed for hosting any size of database on a server which will be accessed by a website or an application.
Source: yahoo answers.
Re: Help really needed :( -
P<3TS - 11.08.2012
So i have to add like this in the script?
pawn Код:
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
OR
pawn Код:
#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_PASS ""
#define MySQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
?
Re: Help really needed :( -
FalconX - 11.08.2012
Quote:
Originally Posted by P<3TS
So i have to add like this in the script?
pawn Код:
#define SQL_HOST "localhost" #define SQL_USER "root" #define SQL_PASS "" #define SQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
OR
pawn Код:
#define MySQL_HOST "localhost" #define MySQL_USER "root" #define MySQL_PASS "" #define MySQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
?
|
Actually it doesn't matter as you are going to use MySQL so the define can be anything you like if you're gonna use
pawn Код:
#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_PASS ""
#define MySQL_DB "DB_NAME"// You'll have to change this to the name of the database created in phpMyAdmin
Then you have to change it in the connection callback too:
pawn Код:
forward ConnectMySQL();
public ConnectMySQL()
{
* * mysql_connect(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS))
*
* * * * if(mysql_ping() == 1)
* * * * { * *
* * * * * * mysql_debug(1);
* * * * printf("[MYSQL]: Connection to `%s` succesful!", MySQL_DB);
* * }
* * else
* * {
* * * * printf("[MYSQL]: [ERROR]: Connection to `%s` failed!", MySQL_DB);
* * }
* * return 1;
}
Else if you're using SQLite define then you will have to use:
pawn Код:
forward ConnectMySQL();
public ConnectMySQL()
{
* * mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
*
* * * * if(mysql_ping() == 1)
* * * * { * *
* * * * * * mysql_debug(1);
* * * * printf("[MYSQL]: Connection to `%s` succesful!", SQL_DB);
* * }
* * else
* * {
* * * * printf("[MYSQL]: [ERROR]: Connection to `%s` failed!", SQL_DB);
* * }
* * return 1;
}
Remove *
Re: Help really needed :( -
P<3TS - 11.08.2012
if i install and use mysql then all the player userfiles are going to database right? then no user files will be in scriptfiles?
Re: Help really needed :( -
kickerbat - 11.08.2012
Your users will have to create new accounts. (unless you code a specific script to check if .ini files exist etc)
But much faster and less server load if you use MySQL.
Heres a Login/Register MySQL script,
http://pastebin.com/eT0xTThB