Raised This Month: $ Target: $400
 0% 

Solved [Optimize] How to...


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 12-20-2017 , 17:10   Re: [Optimize] How to...
Reply With Quote #4

Quote:
Originally Posted by neatek View Post
PHP Code:
Handle StableConnection null// Handle? Or Database?
// here, how to check MySQL Connection?
// != null  ?! or != INVALID_HANDLE? 
Check if != null, meaning connection is not nullified aka connected. or check if == null meaning not connected, and return the error.
Handle? Or Database? -> Database
null or INVALID_HANDLE -> null

Also for connection use this little beauty https://sm.alliedmods.net/new-api/dbi/Database/Connect and for queries https://sm.alliedmods.net/new-api/dbi/Database/Query

Something like this for reference:

PHP Code:
Database StableConnection null

public 
void OnPluginStart()
{
    
Database.Connect(OnDatabaseConnect"my_database_name");
}

public 
void OnDatabaseConnect(Database idb, const char[] errorany data)
{
    if (
idb == null || strlen(error) > 0)
    {
        
PrintToServer("[Mysql] Unable to connect to database (%s)"error);
        
LogError("[Mysql] Unable to connect to database (%s)"error);
        return;
    }
    else
    {
        
//Set to our global variable database named "StableConnection"
        
StableConnection idb;
        
        
//Do a query of your choice upon connection?
        
char sQuery[512];
        
FormatEx(sQuerysizeof(sQuery), "DELETE FROM my_database_name WHERE map = 'de_dust2'"); //Example (non serious) query, change this to whatever you want...
        
        //Send query
        
StableConnection.Query(SQL_ErrorChecksQuery_DBPrio_Normal);

        
//Log Success Print.
        
LogMessage("[Mysq] Successfully connected to database!");
    }
}

//Callback Function to check for errors
public void SQL_ErrorCheck(Handle ownerDBResultSet results, const char[] errorany data)
{
    if (
results == null || strlen(error) > 0)
    {
        
LogError("[Mysql] Query failed! %s"error);
    }

__________________
xines is offline
 


Thread Tools
Display Modes

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 13:23.


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