Quote:
Originally Posted by Neuro Toxin
https://wiki.alliedmods.net/SQL_(Sou...ing)#Threading
Code:
Database hDatabase = null;
void StartSQL()
{
Database.Connect(GotDatabase);
}
public void GotDatabase(Database db, const char[] error, any data)
{
if (db == null)
{
LogError("Database failure: %s", error);
}
else
{
hDatabase = db;
}
}
|
Quote:
Originally Posted by Ilusion9
Code:
Database hDatabase = null;
public void OnPluginStart()
{
Database.Connect(GotDatabase, "sqltest");
}
public void GotDatabase(Database db, const char[] error, any data)
{
if (db == null)
{
LogError("Database failure: %s", error);
}
else
{
hDatabase = db;
}
}
or
Code:
Database hDatabase = null;
public void OnMapStart()
{
if (hDatabase == null)
{
Database.Connect(GotDatabase, "sqltest");
}
}
public void GotDatabase(Database db, const char[] error, any data)
{
if (db == null)
{
LogError("Database failure: %s", error);
}
else
{
hDatabase = db;
}
}
|
thank you.
i can not create table database. please help
my cod:
PHP Code:
#include <sourcemod>
char ZLogFile[PLATFORM_MAX_PATH];
Database hDatabase = null;
public Plugin myinfo =
{
name = "Sql_Test",
author = "Dr.Mohammad",
description = "This Plugin Only For Test",
version = "1.0.0",
url = ""
};
public void OnPluginStart()
{
Database.Connect(GotDatabase, "sqltest");
BuildPath(Path_SM, ZLogFile, sizeof(ZLogFile), "logs/sqltest.log");
}
public void GotDatabase(Database db, const char[] error, any data)
{
if (db == null)
{
LogToFile(ZLogFile, "Database failure: %s", error);
}
else
{
hDatabase = db;
char query[512];
Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS sqltest(name TEXT,steamid TEXT)");
SQL_TQuery(hDatabase, db_Connect_Callback, query);
LogToFile(ZLogFile, "Connection Successfull");
}
}
public void db_Connect_Callback(Handle owner, Handle hndl, const char[] error, any data)
{
if(hndl == INVALID_HANDLE)
{
LogError(error);
LogToFile(ZLogFile, "Database failure: %s", error);
}
}
database.cfg
HTML Code:
"sqltest"
{
"driver" "default"
"host" "localhost"
"database" "sqltest"
"user" "root"
"pass" ""
//"timeout" "0"
"port" "3306"
}