02.02.2014, 13:55
Quote:
If you intend to put it in your gamemode, don't. Most of people using it are using some sort of shared hosting where they don't have power over their db name, and of course aren't allowed to create a new one.
Connecting to that database combined even with a single SQLi is not wise - usually that db is available only to root user, and using root account for your game connection is not wise as well. |
So the script should just assume the database exists and check if there were errors after connecting to it.
In case of errors, shutdown the server might be the best option then.
But there would be no harm in creating the tables inside the script if they don't exist?
pawn Код:
#define mysql_host "127.0.0.1"
#define mysql_user "PowerPC603"
#define mysql_password "MyPass"
#define mysql_database "ppctrucking"
new SQL_db; // Will hold the connectionhandle to the database
public OnFilterScriptInit()
{
SQL_db = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
// Check if there were errors after trying to connect
if (mysql_errno() == 0)
{
printf("Connecting to MySQL was successful");
}
else // The database doesn't exist, so close the connection and shutdown the server after 5 seconds
{
printf("ERROR: Connecting to MySQL failed, shutting down server...");
printf(" ");
printf(" ");
printf(" ");
mysql_close(SQL_db);
SetTimer("ShutdownServer", 5000, false);
return 1;
}
// Rest of code
}
// This timer is used to shutdown the server if connecting to the database failed
forward ShutdownServer();
public ShutdownServer()
{
SendRconCommand("exit");
return 1;
}