Server doesn't seem to connect to the MySQL database
#1

As the title says, when connecting to the database, it's outputting that the attempt failed.

MySQL Logs
Code:
[22:41:41] [ERROR] "mysql_errno" - invalid connection handle (id: 1)
Script to connect to database
pawn Code:
m_iHandle = mysql_connect(SQL_HOSTNAME, SQL_USERNAME, SQL_DATABASE, SQL_PASSWORD, 3306, true, 2);
   
    switch (mysql_errno(m_iHandle))
    {
            case 0: printf("[SQL] Connection to \"%s\" failed! Please check the connection settings...\a", SQL_HOSTNAME);
            default: printf("[SQL] Connection to \"%s\" passed!", SQL_HOSTNAME);
    }
pawn Code:
#define SQL_HOSTNAME "removed"
#define SQL_USERNAME "removed_jimmy"
#define SQL_DATABASE "removed_newdb"
#define SQL_PASSWORD "removed"
Reply
#2

Be sure you have attached your server IP on remote MySql. Also remember free hosting like 000webhost doesn't provided remote Mysql.
Reply
#3

I have, it doesn't even work with a local database, nor I'm hosted at 000webhost, never heard of it anyways.

Quick explanation: Editing an old script, updating everything MySQL related and server doesn't want to connect anymore.
Reply
#4

*) Which mysql version and plugin are you using?
*) Do you get any warnings while you compile?
*) How did you define m_iHandle?
Reply
#5

Quote:
Originally Posted by Maximus0
View Post
*) Which mysql version and plugin are you using?
*) Do you get any warnings while you compile?
*) How did you define m_iHandle?
Latest version BlueG
None
new m_iHandle;
Reply
#6

I have downloaded the latest version of mysql by BlueG and testing your script with some changes.
Try this!

Code:
new m_iHandle = mysql_connect(SQL_HOSTNAME, SQL_USERNAME, SQL_DATABASE, SQL_PASSWORD, 3306, true, 2);
	
	if(mysql_errno() != 0)
		printf("[SQL] Connection to \"%s\" failed! Please check the connection settings...\a", SQL_HOSTNAME);

	printf("[SQL] Connection to \"%s\" passed!", SQL_HOSTNAME);
Reply
#7

It seems to work now, it must be something with the mysql_errno though, because it's still logging this:
Code:
"mysql_errno" - invalid connection handle (id: 1)
Reply
#8

But I didn't manage to see that kind of before with me. Also, I have checked my current log (Everything fine).
Reply
#9

The fact that you censored the hostname tells me that it is not localhost or 127.0.0.1, which it probably should be. For some obscure reason, loads of people get this wrong.
Reply
#10

Quote:
Originally Posted by Vince
View Post
The fact that you censored the hostname tells me that it is not localhost or 127.0.0.1, which it probably should be. For some obscure reason, loads of people get this wrong.
It couldn't be local because it's hosted on another IP on the same dedicated server. (We use a dedicated server with virtual VPSs)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)