MySQL connect - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL connect (
/showthread.php?tid=347196)
MySQL connect -
dannyk0ed - 31.05.2012
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
Re: MySQL connect -
ikey07 - 31.05.2012
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);
}
Re: MySQL connect -
dannyk0ed - 01.06.2012
Should that be under
pawn Код:
public MySQLCheckConnection()
Re: MySQL connect -
ikey07 - 01.06.2012
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;
}
}
}
Re: MySQL connect -
dannyk0ed - 01.06.2012
None of those worked. They dont match the native
Re: MySQL connect -
ikey07 - 01.06.2012
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"
Re: MySQL connect -
dannyk0ed - 01.06.2012
I'm retarded, thanks i got it.
Re: MySQL connect -
dannyk0ed - 01.06.2012
I get this still
pawn Код:
[20:47:20] [MySQL] Error (0): Function: mysql_connect failed, mysql was not initialized on this handle
Re: MySQL connect -
coole210 - 01.06.2012
Add
before mysql_connect
Re: MySQL connect -
dannyk0ed - 01.06.2012
I just realized.