Raised This Month: $32 Target: $400
 8% 

[CS GO] create MySql for game server and web


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 11-06-2018 , 03:23   [CS GO] create MySql for game server and web
Reply With Quote #1

hi guys!!

i started programing for mysql. this cod is true??

PHP Code:
#include <sourcemod>

public Plugin myinfo 
{
    
name "Sql_Test",
    
author "Dr.Mohammad",
    
description "This Plugin Only For Test",
    
version "1.0.0"
    
url ""
};

public 
OnPluginStart()
{
    
char error[255];
    
Database db SQL_Connect("sqltest"trueerrorsizeof(error));

    if (
db == null)
    {
        
PrintToServer("Cannot connect to MySQL Server: %s"error);
    }
    else
    {
        
char query[512];
        
Format(querysizeof(query), "CREATE TABLE IF NOT EXISTS mysqltest(name TEXT,steamid INTEGER NOT NULL)");
        
SQL_TQuery(dbdb_Connect_Callbackquery);
        
PrintToServer("Connection Successfull");
    }
}

public 
void db_Connect_Callback(Handle ownerHandle hndl, const char[] errorany data)
{
    if(
hudl == INVALID_HANDLE)
    {
        
LogError(error);
    }

Dr.Mohammad is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-06-2018 , 04:32   Re: [CS GO] create MySql for game server and web
Reply With Quote #2

Say goodbye to your CPU, using unthreaded connections with a sql that requires internet ( MySQL ). Refer to SQL_TConnect and TQuery. If multiple plugins did that I think the result would be worse. Also I can't find errors but compile and give it a go. Error logs will help.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334

Last edited by eyal282; 11-06-2018 at 04:33.
eyal282 is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 11-06-2018 , 05:06   Re: [CS GO] create MySql for game server and web
Reply With Quote #3

Quote:
Originally Posted by eyal282 View Post
Say goodbye to your CPU, using unthreaded connections with a sql that requires internet ( MySQL ). Refer to SQL_TConnect and TQuery. If multiple plugins did that I think the result would be worse. Also I can't find errors but compile and give it a go. Error logs will help.
What is the best way to write this code?
Dr.Mohammad is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-06-2018 , 05:10   Re: [CS GO] create MySql for game server and web
Reply With Quote #4

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;
	}
}
__________________
Neuro Toxin is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 11-06-2018 , 08:17   Re: [CS GO] create MySql for game server and web
Reply With Quote #5

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;
	}
}
Ilusion9 is offline
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
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 11-06-2018 , 14:29   Re: [CS GO] create MySql for game server and web
Reply With Quote #7

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
         
        
db.Query(db_Connect_Callback"CREATE TABLE IF NOT EXISTS sqltest (name TEXT, steamid TEXT);");
        
LogToFile(ZLogFile"Connection Successfull"); 
    } 


public 
void db_Connect_Callback(Database dbDBResultSet rs, const char[] errorany data)
{
    if(
rs == null
    { 
        
LogError(error); 
        
LogToFile(ZLogFile"Database failure: %s"error); 
    } 

Use the new syntax (Database class):
https://sm.alliedmods.net/new-api/dbi/Database
Ilusion9 is offline
Dr.Mohammad
Senior Member
Join Date: Jan 2016
Location: CSGO Servers
Old 11-10-2018 , 06:38   Re: [CS GO] create MySql for game server and web
Reply With Quote #8

i have errror:
HTML Code:
L 11/10/2018 - 14:56:13: [sql.smx] 1- Connection Successfull
L 11/10/2018 - 14:56:21: [sql.smx] 2- player Dr.Mohammad connected
L 11/10/2018 - 14:56:21: [sql.smx] 2- Database Create Table Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2' at line 1
with this cod:
PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

char ZLogFile[PLATFORM_MAX_PATH];

Database g_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_test, const char[] errorany data)
{
    if (
db_test == null)
    {
        
LogToFile(ZLogFile"1- Connection Loss: %s"error);
    }
    else
    {
        
g_hDatabase db_test;
        
        
g_hDatabase.Query(SQL_Error"CREATE TABLE IF NOT EXISTS players (name TEXT, steamid varchar(32) NOT NULL, ip TEXT, generic TINYINT(32), reservation TINYINT(32), kick TINYINT(32), ban TINYINT(32), unban TINYINT(32), slay TINYINT(32), changemap TINYINT(32), convars TINYINT(32), config TINYINT(32), chat TINYINT(32), vote TINYINT(32), password TINYINT(32), rcon TINYINT(32), cheats TINYINT(32), root TINYINT(32), custom1 TINYINT(32), custom2 TINYINT(32), custom3 TINYINT(32), custom4 TINYINT(32), custom5 TINYINT(32), custom6 TINYINT(32));");
        
LogToFile(ZLogFile"1- Connection Successfull");
    }
}

public 
void SQL_Error(Database db_testDBResultSet hResults, const char[] errorany data)
{
    if(
hResults == null)
    {
        
LogToFile(ZLogFile"2- Database Create Table Error: %s"error);
    }

how to fix??
Dr.Mohammad is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-11-2018 , 15:19   Re: [CS GO] create MySql for game server and web
Reply With Quote #9

You probably need to put all your fields in ` chars due to custom being a keyword.
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode