Raised This Month: $ Target: $400
 0% 

SQL Error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 07:22   SQL Error
Reply With Quote #1

I am facing i error with my SQL i am shared error check attachment

and here is DB Connect handler

PHP Code:
new DB_HOST []  = ""
new DB_USER []  = ""
new DB_PASS []  = ""
new DB_NAME []  = ""
new DB_TABLE [] = "xp_mod"

enum dataStruct sqlModule[6], Handle:sqlTupleHandle:sqlConnection };

new 
gData[dataStruct];

new 
query[2048];

stock db_connect() 
{

    
gData[sqlModule]="mysql";
    
    new 
buffer[128];
    if(
is_module_loaded(gData[sqlModule])<0
    {
        
formatex(buffer,charsmax(buffer),"^r^n[SQL] Error: module ^"%s^" not loaded.^r^n"gData[sqlModule]);
        
log_amx(buffer);
        
set_fail_state(buffer);
        return;
    }
    
    
SQL_GetAffinity(buffercharsmax(buffer));
    
    if(!
equali(buffergData[sqlModule]))
        if(!
SQL_SetAffinity(gData[sqlModule])) {
            
formatex(buffer,charsmax(buffer),"%s Failed to set ^"%s^" affinity!"gData[sqlModule]);
            
log_amx(buffer);
            
set_fail_state(buffer);
            return;
        }
    
    new 
err[256],errNum;
    
gData[sqlTuple] = _:SQL_MakeDbTuple(DB_HOSTDB_USERDB_PASSDB_NAME);
    
gData[sqlConnection] = _:SQL_Connect(gData[sqlTuple], errNumerrcharsmax(err));
    
    if(
gData[sqlTuple]==Empty_Handle || gData[sqlConnection]==Empty_Handle) {
    
        
formatex(buffer,charsmax(buffer),"[SQL] MySQL Error #%d - %s.."errNumerr);
        
log_amx(buffer);
        
set_fail_state(buffer);
    }
    
    
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler","SET NAMES utf8","charset",10);
    
    
server_print("[SQL] connected to: '%s://%s:****@%s/%s/%s'"gData[sqlModule], DB_USERDB_HOSTDB_NAMEDB_TABLE);
    
    
formatex(query,charsmax(query),"CREATE TABLE IF NOT EXISTS %s (id BIGINT NOT NULL %s PRIMARY KEY, name VARCHAR(64), authid VARCHAR(32), ip VARCHAR(20), level INT(11), xp TEXT(11, kill INT(11), death INT(11), he INT(11), knife INT(11), firstbloods INT(11), plant INT(11), defuse INT(11))%s",DB_TABLE,(equali(gData[sqlModule], "mysql"))?"AUTO_INCREMENT":"DEFAULT 0",(equali(gData[sqlModule], "mysql"))?" ENGINE=MyISAM DEFAULT CHARSET=utf8;":"");
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"create",10);
}

public 
QueryHandler(failStateHandle:queryHerr[], errNumdata[], data_size) {
    
    if(
failState==TQUERY_CONNECT_FAILED || failState==TQUERY_QUERY_FAILED || errNum) {
        
log_amx("[SQL] MySQL Error #%d - %s"errNumerr);
        return;
    }
    
    if(
equali(data,"update")||equali(data,"insert")||equali(data,"charset")||equali(data,"create"))
        return;
    
    new 
id data[0];
    new 
rows SQL_NumResults(queryH);
    if(!
rows) {
        static 
query[512], name[64], ip[20];
        
get_user_name(id,name,charsmax(name));
        
clear(name);
        
get_user_ip(id,ip,charsmax(ip),1);
        
formatex(query,charsmax(query),"REPLACE INTO %s (name,authid,ip,xp,level,knife,firstbloods,he,plant,defuse,kill,death) VALUES('%s','%s','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d')",DB_TABLEnamedata[1], ipPlayerXP[id], PlayerLevel[id], g_knife[id], g_firstblood[id], g_heg_plant[id], g_defuse[id], g_kill[id], g_death[id]);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"insert",10);
 
    }

    
PlayerXP[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"xp"));
    
PlayerLevel[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"level"));

    return;
}


stock LoadSqlData(id, const AuthID[]) 
{

    static 
data[32], query[128];
    
data[0]=id;
    
copy(data[1],30,AuthID);
    
    
formatex(query,charsmax(query),"SELECT * FROM %s WHERE authid = '%s'",DB_TABLEAuthID); 
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,data,sizeof(data));

}


stock SaveSqlData(id, const AuthID[]) 
{

    static 
query[256], name[64];
    if(
PlayerXP[id] || PlayerLevel[id]) 
    {
        
get_user_name(id,name,charsmax(name));
        
formatex(query,charsmax(query),"UPDATE %s SET name='%s', xp='%d', level='%d', knife='%d', firstbloods='%d', he='%d', plant='%d', defuse='%d', kill='%d', death='%d' WHERE authid='%s'"DB_TABLEnamePlayerXP[id], PlayerLevel[id], g_knife[id], g_firstblood[id], g_heg_plant[id], g_defuse[id], g_kill[id], g_death[id], AuthID);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"update",10);
    }

Attached Thumbnails
Click image for larger version

Name:	error.png
Views:	121
Size:	66.3 KB
ID:	169475  

Last edited by soumyadip77; 04-25-2018 at 07:22. Reason: PHp tag end
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-25-2018 , 07:42   Re: SQL Error
Reply With Quote #2

You did not close the parenthesis after xp TEXT(11.
__________________
klippy is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 08:09   Re: SQL Error
Reply With Quote #3

me edited but still same error
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-25-2018 , 08:11   Re: SQL Error
Reply With Quote #4

You'll have to paste the new SQL code and the new error (it's most likely similar but not the same), I can't help you otherwise.
__________________

Last edited by klippy; 04-25-2018 at 08:11.
klippy is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 08:13   Re: SQL Error
Reply With Quote #5

okay wait i am pesting
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 08:17   Re: SQL Error
Reply With Quote #6

ERRoR Img => https://imgur.com/a/CBwDvri


PHP Code:
new DB_HOST []  = ""
new DB_USER []  = ""
new DB_PASS []  = ""
new DB_NAME []  = ""
new DB_TABLE [] = "xp_mod"

enum dataStruct sqlModule[6], Handle:sqlTupleHandle:sqlConnection };

new 
gData[dataStruct];

new 
query[2048];

stock db_connect() 
{

    
gData[sqlModule]="mysql";
    
    new 
buffer[128];
    if(
is_module_loaded(gData[sqlModule])<0
    {
        
formatex(buffer,charsmax(buffer),"^r^n[SQL] Error: module ^"%s^" not loaded.^r^n"gData[sqlModule]);
        
log_amx(buffer);
        
set_fail_state(buffer);
        return;
    }
    
    
SQL_GetAffinity(buffercharsmax(buffer));
    
    if(!
equali(buffergData[sqlModule]))
        if(!
SQL_SetAffinity(gData[sqlModule])) {
            
formatex(buffer,charsmax(buffer),"%s Failed to set ^"%s^" affinity!"gData[sqlModule]);
            
log_amx(buffer);
            
set_fail_state(buffer);
            return;
        }
    
    new 
err[256],errNum;
    
gData[sqlTuple] = _:SQL_MakeDbTuple(DB_HOSTDB_USERDB_PASSDB_NAME);
    
gData[sqlConnection] = _:SQL_Connect(gData[sqlTuple], errNumerrcharsmax(err));
    
    if(
gData[sqlTuple]==Empty_Handle || gData[sqlConnection]==Empty_Handle) {
    
        
formatex(buffer,charsmax(buffer),"[SQL] MySQL Error #%d - %s.."errNumerr);
        
log_amx(buffer);
        
set_fail_state(buffer);
    }
    
    
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler","SET NAMES utf8","charset",10);
    
    
server_print("[SQL] connected to: '%s://%s:****@%s/%s/%s'"gData[sqlModule], DB_USERDB_HOSTDB_NAMEDB_TABLE);
    
    
formatex(query,charsmax(query),"CREATE TABLE IF NOT EXISTS %s (id BIGINT NOT NULL %s PRIMARY KEY, name VARCHAR(64), authid VARCHAR(32), ip VARCHAR(20), level INT(11), xp TEXT(11), kill INT(11), death INT(11), he INT(11), knife INT(11), firstbloods INT(11), plant INT(11), defuse INT(11))%s",DB_TABLE,(equali(gData[sqlModule], "mysql"))?"AUTO_INCREMENT":"DEFAULT 0",(equali(gData[sqlModule], "mysql"))?" ENGINE=MyISAM DEFAULT CHARSET=utf8;":"");
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"create",10);
}

public 
QueryHandler(failStateHandle:queryHerr[], errNumdata[], data_size) {
    
    if(
failState==TQUERY_CONNECT_FAILED || failState==TQUERY_QUERY_FAILED || errNum) {
        
log_amx("[SQL] MySQL Error #%d - %s"errNumerr);
        return;
    }
    
    if(
equali(data,"update")||equali(data,"insert")||equali(data,"charset")||equali(data,"create"))
        return;
    
    new 
id data[0];
    new 
rows SQL_NumResults(queryH);
    if(!
rows) {
        static 
query[512], name[64], ip[20];
        
get_user_name(id,name,charsmax(name));
        
clear(name);
        
get_user_ip(id,ip,charsmax(ip),1);
        
formatex(query,charsmax(query),"REPLACE INTO %s (name,authid,ip,xp,level,knife,firstbloods,he,plant,defuse,kill,death) VALUES('%s','%s','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d')",DB_TABLEnamedata[1], ipPlayerXP[id], PlayerLevel[id], g_knife[id], g_firstblood[id], g_heg_plant[id], g_defuse[id], g_kill[id], g_death[id]);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"insert",10);
 
    }

    
PlayerXP[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"xp"));
    
PlayerLevel[id] = SQL_ReadResult(queryH,SQL_FieldNameToNum(queryH"level"));

    return;
}


stock LoadSqlData(id, const AuthID[]) 
{

    static 
data[32], query[128];
    
data[0]=id;
    
copy(data[1],30,AuthID);
    
    
formatex(query,charsmax(query),"SELECT * FROM %s WHERE authid = '%s'",DB_TABLEAuthID); 
    
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,data,sizeof(data));

}


stock SaveSqlData(id, const AuthID[]) 
{

    static 
query[256], name[64];
    if(
PlayerXP[id] || PlayerLevel[id]) 
    {
        
get_user_name(id,name,charsmax(name));
        
formatex(query,charsmax(query),"UPDATE %s SET name='%s', xp='%d', level='%d', knife='%d', firstbloods='%d', he='%d', plant='%d', defuse='%d', kill='%d', death='%d' WHERE authid='%s'"DB_TABLEnamePlayerXP[id], PlayerLevel[id], g_knife[id], g_firstblood[id], g_heg_plant[id], g_defuse[id], g_kill[id], g_death[id], AuthID);
        
SQL_ThreadQuery(gData[sqlTuple],"QueryHandler",query,"update",10);
    }

soumyadip77 is offline
Send a message via Skype™ to soumyadip77
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-25-2018 , 08:55   Re: SQL Error
Reply With Quote #7

It's probably because kill is a reserved keyword. You have to name it something else, like kills. Or use backticks (the ` character) around column names.
__________________

Last edited by klippy; 04-25-2018 at 08:56.
klippy is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 09:29   Re: SQL Error
Reply With Quote #8

i cant under stand " use backticks (the ` character) " explain plz
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-25-2018 , 09:46   Re: SQL Error
Reply With Quote #9

Instead of
Code:
kill
write
Code:
`kill`
.
__________________
klippy is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 04-25-2018 , 10:26   Re: SQL Error
Reply With Quote #10

tried still same error
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
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 04:32.


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