AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL Error (https://forums.alliedmods.net/showthread.php?t=307064)

soumyadip77 04-25-2018 07:22

SQL Error
 
1 Attachment(s)
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);
    }



klippy 04-25-2018 07:42

Re: SQL Error
 
You did not close the parenthesis after xp TEXT(11.

soumyadip77 04-25-2018 08:09

Re: SQL Error
 
me edited but still same error

klippy 04-25-2018 08:11

Re: SQL Error
 
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.

soumyadip77 04-25-2018 08:13

Re: SQL Error
 
okay wait i am pesting

soumyadip77 04-25-2018 08:17

Re: SQL Error
 
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);
    }



klippy 04-25-2018 08:55

Re: SQL Error
 
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.

soumyadip77 04-25-2018 09:29

Re: SQL Error
 
i cant under stand " use backticks (the ` character) " explain plz

klippy 04-25-2018 09:46

Re: SQL Error
 
Instead of
Code:

kill
write
Code:

`kill`
.

soumyadip77 04-25-2018 10:26

Re: SQL Error
 
tried still same error :(


All times are GMT -4. The time now is 04:32.

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