Hello, does anyone knows what is wrong with this code? I don;'t know why but the tables are not created;
PHP Code:
Database g_MainDB;
public void OnPluginStart()
{
Database.Connect(OnConnect, "new_store");
CreateTimer(60.0, AddCredits);
RegConsoleCmd("sm_credits", Cmd_Credits);
}
public Action AddCredits(Handle pTimer)
{
static int Player;
for (Player = 1; Player <= MaxClients; Player++)
{
char Steam[32], sQuery[255];
__STEAM(Player, Steam, 32);
Format(sQuery, 255, "UPDATE new_store SET credits = credits + 1 WHERE steamid = '%s';", Steam);
g_MainDB.Query(Empty, sQuery);
}
}
public void OnConnect(Database db, const char[] error, any data)
{
if(db == null)
SetFailState("Unable to connect to database: %s", error);
g_MainDB = db;
char sQuery[256];
g_MainDB.Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `new_store` \
('name' varchar(128) NOT NULL, 'steamid' varchar(32), 'owned_items_id' varchar(360), 'credits' int(64))");
g_MainDB.Query(OnSQLConnectCallback, sQuery);
}
public void OnSQLConnectCallback(Database db, DBResultSet results, const char[] error, any data)
{
if (results == null)
{
LogError("Query failure: %s", error);
return;
}
}
public void Empty(Handle pDb, Handle pQuery, char[] Error, any Data){}
void __STEAM(int Id, char[] Out, int Size)
{
if (IsFakeClient(Id))
FormatEx(Out, Size, "BOT@%N", Id);
else
GetClientAuthId(Id, AuthId_SteamID64, Out, Size);
}
public Action Cmd_Credits(int iClient, int iArgs)
{
char Steam[32], sQuery[255];
__STEAM(iClient, Steam, 32);
Format(sQuery, 255, "SELECT credits FROM new_store WHERE steamid = '%s'", Steam);
g_MainDB.Query(ReplyCredits, sQuery, iClient);
}
public void ReplyCredits(Handle pDb, Handle pQuery, char[] Error, any Data){
int iCredits = SQL_FetchInt(pQuery, 0);
PrintToChat(Data, "[ \x02STORE \x01] You have \x04%i \x01 Credits", iCredits);
}
public void OnClientPostAdminCheck(int iClient)
{
char Steam[32], sQuery[255], sName[32];
GetClientName(iClient, sName, 32);
__STEAM(iClient, Steam, 32);
Format(sQuery, 255, "INSERT INTO new_store (name, steamid) VALUES ('%s', '%s');", sName, Steam);
g_MainDB.Query(ReplyCredits, sQuery, iClient);
}