Quote:
Originally Posted by Dragokas
Why?
|
If you connect to the database successfully and then you lose connection, you don't have to connect again (if you save the database globally - example - in hDatabase variable. The hDatabase will be valid when the dabatase is on again.
Just connect to the database OnMapStart (or OnConfigsExecuted) and check if the db is null.
PHP Code:
Database hDatabase;
public void OnPluginStart()
{
HookEvent("round_end", Event_SQL_Save, EventHookMode_PostNoCopy);
}
public void OnConfigsExecuted()
{
if (!hDatabase)
{
if (SQL_CheckConfig(HX_DATABASE_CFG))
{
Database.Connect(SQL_Callback_Connect, HX_DATABASE_CFG);
}
}
}
public void SQL_Callback_Connect (Database db, const char[] error, any data)
{
if (!db)
{
LogError("Could not connect to the database: %s", error);
return;
}
hDatabase = db;
}
public void Event_SQL_Save(Event event, const char[] name, bool dontBroadcast)
{
if (!hDatabase)
{
return; // no db connection
}
// ...
// delete g_hDB; // why are you deleting the db here ???
}
This should work well, except deleting the database when the round ends.
__________________