MySQL connect
#1

I dont know if this is correct MySQL connection.

I'm not the best at MySQL but this is my function

pawn Код:
native mysql_connect(const host[], const user[], const pass[], const db[], MySQL:handle = (MySQL:0), auto_reconnect = 0);
-mysql.inc

Mine
pawn Код:
public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[])
{
    FuncLog("MySQLConnect");
    print("MYSQL: Attempting to connect to server...");
    mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, 1);//warning
    if(mysql_ping() == 0)
    {
        print("MYSQL: Database connection established.");
        return 1;
    }
    else
    {
        print("MYSQL: Could not connect! Retrying...");
        mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, 1);//warning
        if(mysql_ping()==0)
        {
           
            return 1;
        }
        else
        {
            print("MYSQL: Could not reconnect to Database! Terminating server...");
            SendRconCommand("exit");
            return 0;
        }
    }
}
pawn Код:
C:\Users\Danny\Desktop\Server\gamemodes\WCRP2.pwn(48913) : warning 213: tag mismatch
C:\Users\Danny\Desktop\Server\gamemodes\WCRP2.pwn(48922) : warning 213: tag mismatch
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


2 Warnings.
pawn Код:
serverlog
[19:21:52] [MySQL] Error (1): Function: mysql_connect failed, mysql was not initialized on this handle.
[19:21:52] MYSQL: Attempting to connect to server...
[19:21:52] *** Audio Plugin: Error binding endpoint for acceptor: Address already in use
Reply
#2

pawn Код:
new MySQL:connection;

public OnGameModeInit()
{
connection= mysql_init(LOG_ONLY_ERRORS, 1);
    if(mysql_connect(SQL_HOST,SQL_USER,SQL_PASS,SQL_DB,connection,1))
    {
        print("Connected ");
    }
}

public OnGameModeExit()
{
mysql_close(connection);
}
Reply
#3

Should that be under
pawn Код:
public MySQLCheckConnection()
Reply
#4

For check is this

pawn Код:
CheckConnection()
{
    if(!mysql_ping(connection))
    {
        return 1;
    }
    else
    {
        mysql_connect(SQL_HOST, SQL_USER, SQL_PASS,SQL_DB,connection,1);
        if(!mysql_ping(connection))
        {
            return 1;
        }
        else
        {
            print( "MySQL Connection is dead, exiting..." );
            SendRconCommand("exit");
            return 0;
        }
    }
}
Reply
#5

None of those worked. They dont match the native
Reply
#6

It does works, dont use public MySQLConnect(sqlhost[], sqluser[], sqlpass[], sqldb[]);

just paste what I posted and at top put this

#define SQL_HOST "127.0.0.1"
#define SQL_USER "user"
#define SQL_PASS "pwd"
#define SQL_DB "db"
Reply
#7

I'm retarded, thanks i got it.
Reply
#8

I get this still
pawn Код:
[20:47:20] [MySQL] Error (0): Function: mysql_connect failed, mysql was not initialized on this handle
Reply
#9

Add

pawn Код:
mysql_init();
before mysql_connect
Reply
#10

I just realized.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)