View Single Post
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 11-06-2018 , 10:45   Re: [CS GO] create MySql for game server and web
Reply With Quote #6

Quote:
Originally Posted by Neuro Toxin View Post
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 View Post
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_SMZLogFilesizeof(ZLogFile), "logs/sqltest.log");
}

public 
void GotDatabase(Database db, const char[] errorany data)
{
    if (
db == null)
    {
        
LogToFile(ZLogFile"Database failure: %s"error);
    }
    else
    {
        
hDatabase db;
        
        
char query[512];
        
Format(querysizeof(query), "CREATE TABLE IF NOT EXISTS sqltest(name TEXT,steamid TEXT)");
        
SQL_TQuery(hDatabasedb_Connect_Callbackquery);
        
LogToFile(ZLogFile"Connection Successfull");
    }
}

public 
void db_Connect_Callback(Handle ownerHandle hndl, const char[] errorany 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"
	}
Dr.Mohammad is offline