verification mysql connect
#1

Hello,
how can I verification if my script is connected to mysql?
I am using this mysql_connect(host,user,dbas,pass), but I don't know does it connected.
Thanks.
Reply
#2

Код:
if(mysql_ping())
{
...//connected
}

if(!mysql_ping())
{
...//not connected
}
Reply
#3

undefined symbol "mysql_ping"

I'm using this: https://sampforum.blast.hk/showthread.php?tid=56564
Reply
#4

pawn Код:
// after mysql_connect
if(mysql_errno() != 0)
{
    print(!"[ERROR] Connection to MySQL failed.");
    SendRconCommand("exit"); // remove this if you don't want your server to be closed.
    return false;
}
Reply
#5

At the top:
new mysql;
Where you connect to database
mysql = mysql_connect(......);
if(mysql_ping(mysql))
{
...//got connection
}
else
{
..//didn't connect
}
Reply
#6

instead of if(mysql_errno() != 0) should be if(mysql_errno() == 0)

it works, thanks for help! rep+
Reply
#7

You need to put it under OnGameModeInit:

pawn Код:
public OnGameModeInit()
{
    mysql_connect(/*.....................*/);
    if(mysql_ping() == 0) printf("failed to connect to db");
    else printf("connected to db");
    return 1;
}
Wups I replied too late
Reply
#8

Danish i know, and i put it into ongamemodeinit, but i don't have mysql_ping function I don't know why, but mysql_errno works.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)