Any MySQL scripter that can help me?

Scripter or interested in scripting? This place just may fancy to your likings!

Moderators: FM, Game Admins, Lead Admins

Locked
User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Any MySQL scripter that can help me?

Post by #YOLO » Sun Jan 29, 2017 12:33 am

Anyone..?

User avatar
Mmartin
Head of Development
Head of Development
Posts: 8055
Joined: Thu Mar 01, 2012 10:05 pm
Ingame name: Lucas Foreman
Location: Basement

Re: Any MySQL scripter that can help me?

Post by Mmartin » Sun Jan 29, 2017 12:34 am

What's your struggle?
Image Mmartin
Development Team SA-MP Tester Team
Image

Will be on absence 20-23 October

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: Any MySQL scripter that can help me?

Post by F Sullivan » Sun Jan 29, 2017 12:40 am

Yes?

User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Re: Any MySQL scripter that can help me?

Post by #YOLO » Sun Jan 29, 2017 12:42 am

Oh, didn't expect you to respond :o, I couldn't even get help on SA:MP forums, not even my hosting company :'(


My script is not connection to the database, I am SURE that the details are right, I even made new users in the cPanel

This is the script:

Code: Select all

/* MYSQL */
#define SQL_HOST ""
#define SQL_USER ""
#define SQL_PASS ""
#define SQL_DB ""

OnGamemodeInit:

Code: Select all

mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
    if(mysql_errno() != 0)
    {
        print("[MYSQL]: Failed to connect with using Following Informations: ");
        printf(" Host: %s | User: %s | Password: ****** | Database: %s", SQL_HOST, SQL_USER, SQL_DB);
  
    }
    else
    {
        printf("[MYSQL]: Connection Success to database: %s !", SQL_DB);

    }

I always get this in the console:

Code: Select all

print("[MYSQL]: Failed to connect with using Following Informations: ");
        printf(" Host: %s | User: %s | Password: ****** | Database: %s", SQL_HOST, SQL_USER, SQL_DB);
And there is no log file so I can check the errors.
I use the R7 plugin.

User avatar
Mmartin
Head of Development
Head of Development
Posts: 8055
Joined: Thu Mar 01, 2012 10:05 pm
Ingame name: Lucas Foreman
Location: Basement

Re: Any MySQL scripter that can help me?

Post by Mmartin » Sun Jan 29, 2017 12:44 am

http://wiki.sa-mp.com/wiki/MySQL/R33#mysql_errno

Code: Select all

Return Values:
Error code, 0 if no error occurred, -1 if invalid connection handle.
There's no error!

edit: if you wanna check whether the connection was successful, do something in the spirit of

Code: Select all

new handle = mysql_connect(...)
if(handle) {
// connected
}else{
// not connected
}
Image Mmartin
Development Team SA-MP Tester Team
Image

Will be on absence 20-23 October

User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Re: Any MySQL scripter that can help me?

Post by #YOLO » Sun Jan 29, 2017 12:52 am

Mmartin wrote:http://wiki.sa-mp.com/wiki/MySQL/R33#mysql_errno

Code: Select all

Return Values:
Error code, 0 if no error occurred, -1 if invalid connection handle.
There's no error!

edit: if you wanna check whether the connection was successful, do something in the spirit of

Code: Select all

new handle = mysql_connect(...)
if(handle) {
// connected
}else{
// not connected
}
Lol... dude.. it worked.. lol you made my day, that errno was an example from SA:MP forums, not even them were able to help me but you did.

When I made this thread I expected it to get locked with the reason "No support here" but you helped me, thanks alot! I am so happy right now.

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: Any MySQL scripter that can help me?

Post by F Sullivan » Sun Jan 29, 2017 12:58 am

Params in the wrong place for the mysql_connect function? Switch SQL_DB & SQL_PASS. Also, you'll want to use a connection handle for querying etc..

User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Re: Any MySQL scripter that can help me?

Post by #YOLO » Sun Jan 29, 2017 12:59 am

F Sullivan wrote:Params in the wrong place for the mysql_connect function? Switch SQL_DB & SQL_PASS.
I am using R6, they are right, it works now anyway :D

Your example is for R40+ as I know.

User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Re: Any MySQL scripter that can help me?

Post by #YOLO » Sun Jan 29, 2017 3:04 pm

Hey, another problem..

I use a clickable textdraw for login and register and I don't want registered players to be able to click on register neither new players to be able to click on login, so I tried to get the rows to find if they are registered or not.
I joined with a new name on the server and clicked on the login, I couldn't log in so it is good but when I clicked on register it told me that I am already registered, here is the code.

Code: Select all

public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
{
    if(_:playertextid != INVALID_TEXT_DRAW)
	{
	    new Query[80],pName[24],string[164];
	    new rows = mysql_num_rows();
	    GetPlayerName(playerid,pName,24);
	    
		if(playertextid == loginscreen[8][playerid])
		{
		    format(Query,sizeof(Query),"SELECT `Username` FROM `players` WHERE `Username` = '%s' LIMIT 1;",pName);
			mysql_query(Query);
			mysql_store_result();
			if(rows == 1)
			{
				format(string,sizeof(string),"Welcome back, %s! \nPlease type your password below to log in!",pName);
				ShowPlayerDialog(playerid,2016,DIALOG_STYLE_INPUT,"Login",string,"Login","");
			}
			else
			{
				ShowPlayerDialog(playerid, 5, DIALOG_STYLE_MSGBOX,"ERROR","This username is not registered! \nPress on Register to register this username.","OK","");
			}
			mysql_free_result();
		}
		else if(playertextid == loginscreen[9][playerid])
		{
		    format(Query,sizeof(Query),"SELECT `Username` FROM `players` WHERE `Username` = '%s' LIMIT 1;",pName);
			mysql_query(Query);
			mysql_store_result();
			if(rows == 0)
			{
				format(string,sizeof(string),"Welcome, %s! \nPlease type a password below to register!",pName);
				ShowPlayerDialog(playerid,2017,DIALOG_STYLE_INPUT,"Register",string,"Register","");
			}
			else
			{
				ShowPlayerDialog(playerid, 6, DIALOG_STYLE_MSGBOX,"ERROR","This username is already registered! \nPress on Login to log in...","OK","");
			}
			mysql_free_result();
		}
	}
    return 1;
}
I tried !rows too, same result.

User avatar
danut
Gangster
Gangster
Posts: 105
Joined: Thu Jan 07, 2016 8:29 pm
Ingame name: Banks

Re: Any MySQL scripter that can help me?

Post by danut » Mon Jan 30, 2017 8:39 am

This version of MySQL is really outdated, you should consider updating to R39 as soon as possible.

As for your problem, you should solve it by using SELECT * because it is really weird SELECTing the same thing you are checking. So your code should look like "SELECT * FROM players WHERE 'Username' = "%s". Tell me if this solved anything.
tu client, io-s patron

User avatar
#YOLO
Wannabe Mafia
Wannabe Mafia
Posts: 273
Joined: Thu Mar 27, 2014 3:30 pm
Ingame name: Corey_Teller

Re: Any MySQL scripter that can help me?

Post by #YOLO » Tue Jan 31, 2017 1:11 am

Fixed it, also updated to r41-2, thanks everyone :D

User avatar
Justus
Retired Administrator
Retired Administrator
Posts: 7240
Joined: Sun May 20, 2012 4:22 am
Ingame name: Harry Bernard
Contact:

Re: Any MySQL scripter that can help me?

Post by Justus » Wed Feb 01, 2017 12:15 am

Alright, closing this, next time don't include your database ip and password!!
Justus
Game Administrator

🛠️Head of Mappers
💻Junior Developer
🤖Level 3 Administrator
👮LSPD PIII

Locked

Return to “Scripting Section”

Who is online

Users browsing this forum: No registered users and 2 guests