Problem with MySQL connection
#1

Hi

I have a problem with my script and I want to say it in the beginning: I'm apprentice in writing in Pawn, so I need clear and easy to understand instructions how to repair my error. Thank you

So, I have a map, I've downloaded it from the internet. I've fixed some errors and built a MySQL database. When it comes to connecting server to database it returns me an error, here it is:
Код:
[MySQL] Error (0): Function: mysql_connect failed, mysql was not initialized on this handle.
Database of course is running and working properly.

I think that the problem is in the MySQLConnect function, so here is the code of it:

pawn Код:
public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[])
{
    print("MySQL: Connecting to MySQL...");
    mysql_connect(sqlhost, sqluser, sqlpass, sqldb);
    if(!mysql_ping())
    {
        print("MySQL: Connected to MySQL.");
        return 1;
    }
    else
    {
        print("MySQL: Connection error, retrying...");
        mysql_connect(sqlhost, sqluser, sqldb, sqlpass);
        if(!mysql_ping())
        {
            print("MySQL: Connection established.");
            mysql_free_result();
            return 1;
        }
        else
        {
            print("MySQL: Can't connect with MySQL.");
            SendRconCommand("exit");
            return 0;
        }
    }
}
If you have any question, just ask.
Reply
#2

Well, what does it print in the main log?
Reply
#3

what plugin is it?
G-sTyLeZzZ's?
StrickenKid's?
Reply
#4

Quote:
Originally Posted by WackoX
Посмотреть сообщение
Well, what does it print in the main log?
Код:
SA-MP Dedicated Server
----------------------
v0.3a R8, ©2005-2010 SA-MP Team

[17:58:47] filterscripts = ""  (string)
[17:58:47] 
[17:58:47] Server Plugins
[17:58:47] --------------
[17:58:47]  Loading plugin: sscanf
[17:58:47] 

[17:58:47]  ===============================

[17:58:47]       sscanf plugin loaded.     

[17:58:47]    © 2009 Alex "******" Cole

[17:58:47]  ===============================

[17:58:47]   Loaded.
[17:58:47]  Loading plugin: streamer
[17:58:47] 

*** Streamer Plugin v2.3.3 by Incognito loaded ***


[17:58:47]   Loaded.
[17:58:47]  Loading plugin: mysql
[17:58:47]  SA:MP MySQL Plugin v2.0 Loaded.
[17:58:48]   Loaded.
[17:58:48]  Loaded 3 plugins.

[17:58:48] [MySQL] Thread running. Threadsafe: Yes.
[17:58:48] 
[17:58:48] Filter Scripts
[17:58:48] ---------------
[17:58:48]   Loaded 0 filter scripts.

[17:58:48] MySQL: Connecting to MySQL...
[17:58:48] [MySQL] Error (0): Function: mysql_connect failed, mysql was not initialized on this handle.
Quote:
Originally Posted by The Toni
Посмотреть сообщение
what plugin is it?
G-sTyLeZzZ's?
StrickenKid's?
StrickenKid's
Reply
#5

Put mysql_init(); above mysql_connect(); like this:

pawn Код:
public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[])
{
    print("MySQL: Connecting to MySQL...");
    mysql_init();
    mysql_connect(sqlhost, sqluser, sqlpass, sqldb);
    if(!mysql_ping())
    {
        print("MySQL: Connected to MySQL.");
        return 1;
    }
    else
    {
        print("MySQL: Connection error, retrying...");
        mysql_connect(sqlhost, sqluser, sqldb, sqlpass);
        if(!mysql_ping())
        {
            print("MySQL: Connection established.");
            mysql_free_result();
            return 1;
        }
        else
        {
            print("MySQL: Can't connect with MySQL.");
            SendRconCommand("exit");
            return 0;
        }
    }
}
Reply
#6

It have worked! I wonder how I could be so dumbass to not see that Thank you so much, thread can be closed.

PS. Is there any way to reward you, such as reputation system or something like that?
Reply
#7

It doesn't need to be as much as that, you can just do this, Stricken's automatically tells you if you are connected are not

pawn Код:
//Under OnGameModeInIt is easy as this:
new MySQL:connection = mysql_init(1); //Log Everything
mysql_connect(sql_host, sql_user, sql_pass, sql_db, 1, connection);
It will tell you if you are connected or not
Reply
#8

There is no reputation system but I think it should be added.
Reply
#9

No problem man, I just do it for free :P

Quote:
Originally Posted by The Toni
Посмотреть сообщение
It doesn't need to be as much as that, you can just do this, Stricken's automatically tells you if you are connected are not

pawn Код:
//Under OnGameModeInIt is easy as this:
new MySQL:connection = mysql_init(1); //Log Everything
mysql_connect(sql_host, sql_user, sql_pass, sql_db, 1, connection);
It will tell you if you are connected or not
Yeah true, but I just showed him how to fix HIS code, I didn't want to completely change it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)