Raised This Month: $51 Target: $400
 12% 

Sqlx problem.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 12-29-2012 , 11:50   Sqlx problem.
Reply With Quote #1

hello everyone,

I'm trying to learn how to connect the plugin to DB SQL ,
i opend new db
and i use this plugin:
PHP Code:
#include <amxmodx>
#include <sqlx>

#define PLUGIN "Tutorial"
#define VERSION "1.0"
#define AUTHOR "Grim"

// Ur Mysql Information


new Host[]     = "82.80.17.122"
new User[]    = "glowed1_glowed1"
new Pass[]     = "*******"
new Db[]     = "    ******"



new Handle:g_SqlTuple
new g_Error[512]


new 
iExp[33]

// Pcvar's
new cKill
new cHeadshot
new cDeath

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("DeathMsg""Event_DeathMsg""a"// Register death event
    
    // register the Pcvar's
    
cKill register_cvar("exp_kill""2")
    
cHeadshot register_cvar("exp_headshot""4")
    
cDeath register_cvar("exp_death""1")
    
    
set_task(1.0"MySql_Init"// set a task to activate the mysql_init
}

public 
MySql_Init()
{
    
// we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
   
    
// ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle)
        
// stop the plugin with an error message
        
set_fail_state(g_Error)
       
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS tutorial (steamid varchar(32),exp INT(11))")

    if(!
SQL_Execute(Queries))
    {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
       
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
   
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection)   
}

public 
plugin_end()
{
    
// free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    
SQL_FreeHandle(g_SqlTuple)
}

public 
Load_MySql(id)
{
    new 
szSteamId[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    new 
Data[1]
    
Data[0] = id
    
    
//we will now select from the table `tutorial` where the steamid match
    
format(szTemp,charsmax(szTemp),"SELECT * FROM `tutorial` WHERE (`tutorial`.`steamid` = '%s')"szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)
    }

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1
    {
        
//.if there are no results found
        
        
new szSteamId[32]
        
get_user_authid(idszSteamIdcharsmax(szSteamId)) // get user's steamid
        
        //  if its still pending we can't do anything with it
        
if (equal(szSteamId,"ID_PENDING"))
            return 
PLUGIN_HANDLED
            
        
new szTemp[512]
        
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp),"INSERT INTO `tutorial` ( `steamid` , `exp`)VALUES ('%s','0');",szSteamId)
        
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    } 
    else 
    {
        
// if there are results found
        
iExp[id]         = SQL_ReadResult(Query1)
    }
    
    return 
PLUGIN_HANDLED
}

public 
Save_MySql(id)
{
    new 
szSteamId[32], szName[32], szTemp[512]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
    
// Here we will update the user hes information in the database where the steamid matches.
    
format(szTemp,charsmax(szTemp),"UPDATE `tutorial` SET `exp` = '%i' WHERE `tutorial`.`steamid` = '%s';",iExp[id], szSteamId)
    
SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    
SQL_FreeHandle(Query)
    
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
Load_MySql(id)
}

public 
client_disconnect(id)
{
    
Save_MySql(id)
}

public 
Event_DeathMsg()
{
    new 
iKiller read_data(1// read the data to get the killer and victim
    
new iVictim read_data(2)
    
    if(
is_user_alive(iKiller)) // Check if the killer is alive in case he killed himself
    
{
        if(
read_data(3))
        {
            
iExp[iKiller] += get_pcvar_num(cHeadshot// Add the amount of the Pcvar to iExp
        
}
        else
        {
            
iExp[iKiller] += get_pcvar_num(cKill)
        }
    }
    
iExp[iVictim] -= get_pcvar_num(cDeath// Decrease the amount of the Pcvar from iExp

and idk what im doing wrong , its send errors to logs :

Quote:
L 12/29/2012 - 18:265: Start of error session.
L 12/29/2012 - 18:265: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20121229.log")
L 12/29/2012 - 18:265: [AMXX] Plugin ("Check.amxx") is setting itself as failed.
L 12/29/2012 - 18:265: [AMXX] Plugin says: Host 'IGLD-84-228-113-70.inter.net.il' is not allowed to connect to this MySQL server
L 12/29/2012 - 18:265: [AMXX] Displaying debug trace (plugin "zPlayedTime.amxx")
L 12/29/2012 - 18:265: [AMXX] Run time error 1: forced exit
L 12/29/2012 - 18:265: [AMXX] [0] Check.sma::MySql_Init (line 53)
im sure the details are correct ( i checked 10 times ) and i tried also another 2 plugins .
and its the same problem ..

im using DirectAdmin Panel so i opened the db from there .

idk what im doing wrong /=
somone can help me please ..
Mr.Waffle is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 12-29-2012 , 11:58   Re: Sqlx problem.
Reply With Quote #2

It looks like your MYSQL doesn't allow remote access. Are you using free web hosting?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 12-29-2012 , 12:04   Re: Sqlx problem.
Reply With Quote #3

yes im using free web hosting, so this is the problem ? /=
Mr.Waffle is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 12-29-2012 , 12:15   Re: Sqlx problem.
Reply With Quote #4

Yes, that is the problem. Try hosting it yourself or get paid hosting.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 12-29-2012 , 13:13   Re: Sqlx problem.
Reply With Quote #5

thanks, can u give me a paid hosting ? that ur Recommend ..
cuz i dont wanna buy one with the same problem.
thanks.
Mr.Waffle is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 12-29-2012 , 13:32   Re: Sqlx problem.
Reply With Quote #6

Quote:
Originally Posted by Mr.Waffle View Post
thanks, can u give me a paid hosting ?
I use hostgator.
Quote:
Originally Posted by Mr.Waffle View Post
i dont wanna buy one with the same problem.
thanks.
You can always ask the hosting company "do they allow remote access" before purchasing hosting.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
sami_spt
Veteran Member
Join Date: Sep 2012
Location: I<3 pussy cats
Old 12-29-2012 , 17:46   Re: Sqlx problem.
Reply With Quote #7

Use localhost.. less lagg and better.!
sami_spt is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 12-29-2012 , 17:48   Re: Sqlx problem.
Reply With Quote #8

Quote:
Originally Posted by sami_spt View Post
Use localhost.. less lagg and better.!
Not everyone can use a local SQL database. Not everyone has the knowledge required to set up a stable and secure SQL database
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Mr.Waffle
Senior Member
Join Date: Dec 2011
Old 12-29-2012 , 18:07   Re: Sqlx problem.
Reply With Quote #9

i think i sould use localhost becuze when i opened the db its said "host : localhost."
but there is a same problem .
maybe the problem is what wickedd told..
i will buy a host soon and i will check it.
Mr.Waffle is offline
petraunas
Junior Member
Join Date: Mar 2015
Old 10-04-2015 , 11:36   Re: Sqlx problem.
Reply With Quote #10

I think I had this issue before. I set 127.0.0.1 instead of localhost and worked just right fine for me.
__________________
Looking for plugins.
petraunas 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 09:31.


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