ok, you obviously tried to help yourself.
i like that, so here's some more help:
i quickly wrote this to push you in the right direction. i guess almost everything you need is in there.
this is completely untested and you also need to adapt the db name and stuff. this is just meant as an example which you can heavily copy+paste.
but please, still try to understand what's happening. if you have any further questions, feel free to ask.
PHP Code:
#pragma semicolon 1
#include <sourcemod>
new Handle:g_hDatabase = INVALID_HANDLE;
new Handle:g_hCvarDBName;
new String:g_sDatabaseName[64];
public OnPluginStart() {
g_hCvarDBName = CreateConVar("sm_yourpluginname_dbname", "admintools", "Use this db for your plugin.", FCVAR_PLUGIN);
HookConVarChange(g_hCvarDBName, Cvar_Changed);
RegConsoleCmd("sm_querydb", Command_QueryDB);
RegConsoleCmd("sm_querydb_unixtimestamp", Command_QueryDBUnix);
}
public Cvar_Changed(Handle:convar, const String:oldValue[], const String:newValue[]) {
OnConfigsExecuted();
}
public OnConfigsExecuted() {
GetConVarString(g_hCvarDBName,g_sDatabaseName,sizeof(g_sDatabaseName));
SQL_TConnect(SQL_Connected, g_sDatabaseName);
}
public SQL_Connected(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(g_hDatabase != INVALID_HANDLE) {
CloseHandle(g_hDatabase);
g_hDatabase = INVALID_HANDLE;
}
if (hndl == INVALID_HANDLE)
{
LogError("Database error: %s", error);
return;
}
g_hDatabase = hndl;
LogMessage("Connected successfully to database");
}
public Action:Command_QueryDB(client,args) {
if(g_hDatabase == INVALID_HANDLE)
return;
decl String:sSteamID[32];
GetClientAuthString(client, sSteamID, sizeof(sSteamID));
decl String:sQuery[1024];
Format(sQuery, sizeof(sQuery), "SELECT last_date FROM premium_users_dust2only WHERE steam_id = '%s'", sSteamID);
SQL_TQuery(g_hDatabase, SQL_ProcessResult, sQuery, client, DBPrio_High);
}
public SQL_ProcessResult(Handle:db, Handle:hQuery, const String:error[], any:client)
{
if(hQuery == INVALID_HANDLE) {
LogError("Query failed: %s", error);
return;
}
if(SQL_FetchRow(hQuery))
{
new String:sDate[255];
SQL_FetchString(hQuery, 0, sDate, sizeof(sDate));
PrintToChat(client, "Expiry date: %s", sDate);
}
CloseHandle(hQuery);
}
public Action:Command_QueryDBUnix(client,args) {
if(g_hDatabase == INVALID_HANDLE)
return;
decl String:sSteamID[32];
GetClientAuthString(client, sSteamID, sizeof(sSteamID));
decl String:sQuery[1024];
Format(sQuery, sizeof(sQuery), "SELECT UNIX_TIMESTAMP(TIMESTAMP(last_date))-UNIX_TIMESTAMP(now()) AS seconds_left FROM premium_users_dust2only WHERE steam_id = '%s'", sSteamID);
SQL_TQuery(g_hDatabase, SQL_ProcessResultUnix, sQuery, client, DBPrio_High);
}
public SQL_ProcessResultUnix(Handle:db, Handle:hQuery, const String:error[], any:client)
{
if(hQuery == INVALID_HANDLE) {
LogError("Query failed: %s", error);
return;
}
if(SQL_FetchRow(hQuery))
{
new iSecondsLeft = SQL_FetchInt(hQuery, 0);
if(iSecondsLeft > 0) {
PrintToChat(client, "Seconds left: %i", iSecondsLeft);
}
}
CloseHandle(hQuery);
}
__________________