Mysql doesnt connect..
#1

Hey guys i got a problem with my mysql .. it doesnt connect to the DB when i use G-stylez plugin but when i use Adrelina DJ it does here's the line's
pawn Код:
forward MySQLConnect(sqlhost[],sqluser[],sqldatabase[],sqlpassword[]);
forward MySQLDisconnect();
forward MySQLCheckConnection();
forward MySQLUpdateBuild(query[], sqlplayerid);
forward MySQLUpdateFinish(query[], sqlplayerid);
forward MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint);
forward MySQLUpdatePlayerIntSingle(sqlplayerid, sqlvalname[], sqlupdateint);
forward MySQLUpdatePlayerFlo(query[], sqlplayerid, sqlvalname[], Float:sqlupdateflo);
forward MySQLUpdatePlayerStr(query[], sqlplayerid, sqlvalname[], sqlupdatestr[]);
forward MySQLCheckAccount(sqlplayersname[]);
forward MySQLCheckAccountLocked(sqlplayerid);
forward MySQLCheckIPBanned(ip[]);
forward MySQLFetchAcctSingle(sqlplayerid, sqlvalname[], sqlresult[]);
forward MySQLFetchAcctRecord(sqlplayerid, sqlresult[]);
forward MySQLCreateAccount(newplayersname[], newpassword[]);
forward MySQLAddLoginRecord(sqlplayerid, ipaddr[]);

public MySQLConnect(sqlhost[],sqluser[],sqldatabase[],sqlpassword[]) // by Luk0r
{
    print("MYSQL: Attempting to connect to server...");
    mysql_connect(sqlhost, sqluser, sqldatabase, sqlpassword);
    if(mysql_ping()==0)
    {
        print("MYSQL: Database connection established.");
        return 1;
    }
    else
    {
        print("MYSQL: Connection error, retrying...");
        mysql_connect(sqlhost, sqluser, sqldatabase, sqlpassword);
        if(mysql_ping()==0)
        {
            print("MYSQL: Reconnection successful. We can continue as normal.");
            return 1;
        }
        else
        {
            print("MYSQL: Could not reconnect to server, terminating server...");
            SendRconCommand("exit");
            return 0;
        }
    }
}

public MySQLDisconnect() // by Luk0r
{
    mysql_close();
    return 1;
}

public MySQLCheckConnection() // by Luk0r
{
    if(mysql_ping()==0)
    {
        return 1;
    }
    else
    {
        print("MYSQL: Connection seems dead, retrying...");
        MySQLDisconnect();
        MySQLConnect(SQL_HOST,SQL_USER,SQL_DATABASE,SQL_PASSWORD);
        if(mysql_ping()==0)
        {
            print("MYSQL: Reconnection successful. We can continue as normal.");
            return 1;
        }
        else
        {
            print("MYSQL: Could not reconnect to server, terminating server...");
            SendRconCommand("exit");
            return 0;
        }
    }
}

public MySQLUpdateBuild(query[], sqlplayerid) // by Luk0r
{
    new querylen = strlen(query);
    //new querymax = sizeof(query);
    new querymax = MAX_STRING;
    if (querylen < 1) format(query, querymax, "UPDATE players SET ");
    else if (querymax-querylen < 50) // make sure we're being safe here
    {
        // query is too large, send this one and reset
        new whereclause[32];
        format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
        strcat(query, whereclause, querymax);
        mysql_query(query);
        //if (DEBUG) SQLLog(query);
        format(query, querymax, "UPDATE players SET ");
    }
    else if (strfind(query, "=", true) != -1) strcat(query, ",", MAX_STRING);
    return 1;
}

public MySQLUpdateFinish(query[], sqlplayerid) // by Luk0r
{
    if (strcmp(query, "WHERE id=", false) == 0) mysql_query(query);
    else
    {
        new whereclause[32];
        format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
        strcat(query, whereclause, MAX_STRING);
        mysql_query(query);
        format(query, MAX_STRING, "UPDATE players SET ");
    }
    return 1;
}

public MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint) // by Luk0r
{
    MySQLUpdateBuild(query, sqlplayerid);
    new updval[64];
    format(updval, sizeof(updval), "%s=%d", sqlvalname, sqlupdateint);
    strcat(query, updval, MAX_STRING);
    return 1;
}

public MySQLUpdatePlayerFlo(query[], sqlplayerid, sqlvalname[], Float:sqlupdateflo) // by Luk0r
{
/*  new query[128];
    format(query, sizeof(query), "UPDATE players SET %s=%f WHERE id=%d", sqlvalname, sqlupdateflo, sqlplayerid);
    mysql_query(query);*/

    new flotostr[32];
    format(flotostr, sizeof(flotostr), "%f", sqlupdateflo);
    MySQLUpdatePlayerStr(query, sqlplayerid, sqlvalname, flotostr);
    return 1;
}

public MySQLUpdatePlayerStr(query[], sqlplayerid, sqlvalname[], sqlupdatestr[]) // by Luk0r
{
    MySQLUpdateBuild(query, sqlplayerid);
    new escstr[128];
    new updval[128];
    mysql_real_escape_string(sqlupdatestr, escstr);
    format(updval, sizeof(updval), "%s='%s'", sqlvalname, escstr);
    strcat(query, updval, MAX_STRING);
    return 1;
}

public MySQLUpdatePlayerIntSingle(sqlplayerid, sqlvalname[], sqlupdateint) // by Luk0r
{
    new query[128];
    format(query, sizeof(query), "UPDATE players SET %s=%d WHERE id=%d", sqlvalname, sqlupdateint, sqlplayerid);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    return 1;
}

public MySQLCheckAccount(sqlplayersname[]) // by Luk0r
{
    new query[128];
    new escstr[MAX_PLAYER_NAME];
    mysql_real_escape_string(sqlplayersname, escstr);
    format(query, sizeof(query), "SELECT id FROM players WHERE LOWER(Name) = LOWER('%s') LIMIT 1", escstr);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    mysql_store_result();
    if (mysql_num_rows()==0)
    {
        return 0;
    }
    else
    {
        new strid[32];
        new intid;
        mysql_fetch_row(strid);
        intid = strval(strid);
        mysql_free_result();
        return intid;
    }
}

public MySQLCheckAccountLocked(sqlplayerid)
{
    new query[64];
    new lockedboolstr[4];
    format(query, sizeof(query), "SELECT Locked FROM players WHERE id=%d LIMIT 1", sqlplayerid);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    mysql_store_result();
    mysql_fetch_row(lockedboolstr);
    if (strval(lockedboolstr) != 0)
    {
        mysql_free_result();
        return 1;
    }
    mysql_free_result();
    return 0;
}

public MySQLCheckIPBanned(ip[])
{
    new query[64];
    format(query, sizeof(query), "SELECT type FROM bans WHERE ip = '%s' AND inactive = 0 ORDER BY id DESC LIMIT 1", ip);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    mysql_store_result();
    if (mysql_num_rows() != 0)
    {
        new bantypestr[4];
        new bantypeint;
        mysql_fetch_row(bantypestr);
        bantypeint = strval(bantypestr);
        mysql_free_result();
        return bantypeint;
    }
    return 0;
}

public MySQLFetchAcctSingle(sqlplayerid, sqlvalname[], sqlresult[])
{
    new query[128];
    format(query, sizeof(query), "SELECT %s FROM players WHERE id = %d LIMIT 1", sqlvalname, sqlplayerid);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    mysql_store_result();
    if(mysql_fetch_row(sqlresult)==1)
    {
        mysql_free_result();
        return 1;
    }
    return 0;
}

public MySQLFetchAcctRecord(sqlplayerid, sqlresult[]) // by Luk0r
{
    new query[64];
    format(query, sizeof(query), "SELECT * FROM players WHERE id = %d LIMIT 1", sqlplayerid);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    mysql_store_result();
    if(mysql_fetch_row(sqlresult)==1)
    {
        mysql_free_result();
        return 1;
    }
    return 0;
}

public MySQLCreateAccount(newplayersname[], newpassword[]) // by Luk0r
{
    new query[128];
    new sqlplyname[64];
    new sqlpassword[64];
    mysql_real_escape_string(newplayersname, sqlplyname);
    mysql_real_escape_string(newpassword, sqlpassword);
    format(query, sizeof(query), "INSERT INTO players (Name, Password) VALUES ('%s', '%s')", sqlplyname, sqlpassword);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    new newplayersid = MySQLCheckAccount(newplayersname);
    if (newplayersid != 0)
    {
        return newplayersid;
    }
    return 0;
}

public MySQLAddLoginRecord(sqlplayerid, ipaddr[]) // by Luk0r
{
    new query[128];
    new escip[16];
    mysql_real_escape_string(ipaddr, escip);
    format(query, sizeof(query), "INSERT INTO logins (time,ip,userid) VALUES (UNIX_TIMESTAMP(),'%s',%d)", escip, sqlplayerid);
    mysql_query(query);
    //if (DEBUG) SQLLog(query);
    return 1;
}
Need urgent help..
Reply
#2

This is from Moderntopia or CW. Post at that topic.
Reply
#3

1. CW is closed
2.I'm modifing it to learn mysql...
3.Come on :P Any idea? It work's with Adrelina DJ but it's so buggy.. i want it to work with G-stylez Plugin..
Reply
#4

Quote:
Originally Posted by »Julian™«
1. CW is closed
2.I'm modifing it to learn mysql...
3.Come on :P Any idea? It work's with Adrelina DJ but it's so buggy.. i want it to work with G-stylez Plugin..
No it isnt:

http://forum.sa-mp.com/index.php?topic=69637.0

Reply
#5

The guy's aint developing it..
Reply
#6

Quote:
Originally Posted by »Julian™«
The guy's aint developing it..
What you're saying doesn't make any sense at all:

Quote:
Originally Posted by »Julian™«
Hey guys i got a problem with my mysql .. it doesnt connect to the DB when i use G-stylez plugin but when i use Adrelina DJ it does here's the line's
The reason why it doesnt work is because CW-RP using Adrelin's mysql plugin so that's is why. IF you want it to make it work with G-Stylzz you have to remake the functions
Reply
#7

THat's what ive done .. Removed Strtrok and replaced it with another line and removed samp_mysql replaced with mysql .. Problem is the CONNECTION .. if you can recode it or tell me what to do i'll be happy..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)