Example of connection:
PHP Code:
#include < amxmodx >
#include < sqlx >
new Handle:g_hSqlCon
public plugin_init ( )
{
register_plugin ( ..., ..., ..., )
mysql_init ( )
}
mysql_init ( )
{
new szHost [ 32 ]
new szUser [ 32 ]
new szPass [ 32 ]
new szDtbe [ 32 ]
new szError [ 128 ]
new iError
get_pcvar_string ( "amx_sql_host", szHost, sizeof ( szHost ) - 1 )
get_pcvar_string ( "amx_sql_user", szUser, sizeof ( szUser ) - 1 )
get_pcvar_string ( "amx_sql_pass", szPass, sizeof ( szPass ) - 1 )
get_pcvar_string ( "amx_sql_db", szDtbe, sizeof ( szDtbe ) - 1 )
new Handle:hSqlTpl = SQL_MakeDbTuple ( szHost, szUser, szPass, szDtbe )
g_hSqlCon = SQL_Connect ( hSqlTpl, iError, szError, sizeof ( szError ) - 1 )
if ( !g_hSqlCon )
{
// .. connection failed
}
// .. successfully connected
public plugin_end ( ) // .. this is not so necessary
SQL_FreeHandle ( g_hSqlCon )