MySQL problem
#1

Hello. I have a problem with a MySQL command. I receive this error using crashdetect:

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3z, ©2005-2014 SA-MP Team

[13:54:13] 
[13:54:13] Server Plugins
[13:54:13] --------------
[13:54:13]  Loading plugin: mysql
[13:54:13]  SA:MP MySQL Plugin v2.1.1 Loaded.
[13:54:13]   Loaded.
[13:54:13]  Loading plugin: sscanf
[13:54:13] [MySQL] Thread running. Threadsafe: Yes.
[13:54:13] 

[13:54:13]  ===============================

[13:54:13]       sscanf plugin loaded.     

[13:54:13]          Version:  2.8.1        

[13:54:13]    © 2012 Alex "******" Cole  

[13:54:13]  ===============================

[13:54:13]   Loaded.
[13:54:13]  Loading plugin: streamer
[13:54:13] 

*** Streamer Plugin v2.6.1 by Incognito loaded ***

[13:54:13]   Loaded.
[13:54:13]  Loading plugin: crashdetect
[13:54:13]   CrashDetect v4.13 is OK.
[13:54:13]   Loaded.
[13:54:13]  Loaded 4 plugins.

[13:54:13] 
[13:54:13] Ban list
[13:54:13] --------
[13:54:13]  Loaded: samp.ban
[13:54:13] 
[13:54:13] 
[13:54:13] Filterscripts
[13:54:13] ---------------
[13:54:13]   Loading filterscript 'gl_realtime.amx'...
[13:54:13]   Loaded 1 filterscripts.

[13:54:13] Houses not loaded yet.
[13:54:13] 0
[13:54:13] [debug] Server crashed while executing house.amx
[13:54:13] [debug] AMX backtrace:
[13:54:13] [debug] #0 native mysql_query () [10007780] from mysql.DLL
[13:54:13] [debug] #1 000127fc in ?? () from house.amx
[13:54:13] [debug] #2 00007b98 in public SSCANF_OnGameModeInit () from house.amx
[13:54:13] [debug] #3 00000654 in public zcmd_OnGameModeInit () from house.amx
[13:54:13] [debug] #4 native CallLocalFunction () [00472ad0] from samp-server.exe
[13:54:13] [debug] #5 00000124 in public OnGameModeInit () from house.amx
[13:54:13] [debug] Native backtrace:
[13:54:13] [debug] #0 100042ea in ?? () from plugins\mysql.DLL
[13:54:13] [debug] #1 10007820 in ?? () from plugins\mysql.DLL
[13:54:13] [debug] #2 004010b6 in ?? () from samp-server.exe
[13:54:13] [debug] #3 634f58ca in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #4 634f774f in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #5 634f0834 in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #6 634f591a in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #7 00472dde in ?? () from samp-server.exe
[13:54:13] [debug] #8 004010b6 in ?? () from samp-server.exe
[13:54:13] [debug] #9 634f58ca in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #10 634f774f in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #11 634f0834 in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #12 634f591a in ?? () from plugins\crashdetect.DLL
[13:54:13] [debug] #13 0046e624 in ?? () from samp-server.exe
[13:54:13] [debug] #14 65646f6d in ?? () from samp-server.exe
[13:54:13] [debug] #15 6f682f73 in ?? () from samp-server.exe
[13:54:13] [debug] #16 2e657375 in ?? () from samp-server.exe
[13:54:13] [debug] #17 00786d61 in ?? ()
I posted this problem some time ago, but I couldn't find a solution.

The stock I'm using:

pawn Код:
stock MySQL_LoadHouse()
{
    new savingstring[700];
    print("0");
    mysql_query("SELECT * FROM houses");
    print("1");
    mysql_store_result();
    print("2");
    for(new hid = 1; hid < MAX_HOUSES && mysql_fetch_row(savingstring, "|"); hid++)
        {
        print("3");
        mysql_fetch_field("id",savingstring);
        HouseInfo[hid][hId]=strval(savingstring);
        print("4");
        mysql_fetch_field("owner",savingstring);
        strins(HouseInfo[hid][hOwner],savingstring,1);
        print("5");
        mysql_fetch_field("level",savingstring);
        HouseInfo[hid][hLevel]=strval(savingstring);
        print("6");
        mysql_fetch_field("text",savingstring);
        strins(HouseInfo[hid][hText],savingstring,1);
        print("7");
        mysql_fetch_field("renters",savingstring);
        HouseInfo[hid][hRenters]=strval(savingstring);
        print("8");
        mysql_fetch_field("rentprice",savingstring);
        HouseInfo[hid][hRentprice]=strval(savingstring);
        print("9");
        mysql_fetch_field("rentable",savingstring);
        HouseInfo[hid][hRentable]=strval(savingstring);
        print("10");
        mysql_fetch_field("price",savingstring);
        HouseInfo[hid][hPrice]=strval(savingstring);
        print("11");
        mysql_fetch_field("upgrade",savingstring);
        HouseInfo[hid][hUpgrade]=strval(savingstring);
        print("12");
        mysql_fetch_field("locked",savingstring);
        HouseInfo[hid][hLocked]=strval(savingstring);
        print("13");
        mysql_fetch_field("enterX",savingstring);
        HouseInfo[hid][hEnterX]=strval(savingstring);
        print("14");
        mysql_fetch_field("enterY",savingstring);
        HouseInfo[hid][hEnterY]=strval(savingstring);
        print("15");
        mysql_fetch_field("enterZ",savingstring);
        HouseInfo[hid][hEnterZ]=strval(savingstring);
        print("16");
        mysql_fetch_field("exitX",savingstring);
        HouseInfo[hid][hExitX]=strval(savingstring);
        print("17");
        mysql_fetch_field("exitY",savingstring);
        HouseInfo[hid][hExitY]=strval(savingstring);
        print("18");
        mysql_fetch_field("exitZ",savingstring);
        HouseInfo[hid][hExitZ]=strval(savingstring);
        print("19");
        mysql_fetch_field("interior",savingstring);
        HouseInfo[hid][hInterior]=strval(savingstring);
        print("20");
        mysql_fetch_field("virtual",savingstring);
        HouseInfo[hid][hVirtual]=strval(savingstring);
        print("21");
        }
    mysql_free_result();
}
And in my OnGameModeInit I have this:

pawn Код:
print("Houses not loaded yet.");
    MySQL_LoadHouse();
    print("Houses loaded");
Also, this, near the other defines:

pawn Код:
#define MAX_HOUSES 3
So, what is wrong with this? I really can't figure out. I will be very grateful to anyone helps me out with this.
Reply
#2

The MySQL plugin by StrickenKid is really old and out-dated. He hasn't joined since 2012 so he's not going to update it again and/or fix bugs.

All I can suggest you is to switch to BlueG's MySQL plugin which is up-to-date (latest version is R37) and it's much more faster from this plugin.
Reply
#3

Maybe a dpwnload link? And there are no changes in the script because of the update, right?
Reply
#4

https://github.com/pBlueG/SA-MP-MySQL/releases

There are many changes, threaded queries and ORM system. Non-threaded queries were added again but it's not exactly the same; however, I recommend you to use threaded queries.

Tutorial about threaded queries: https://sampforum.blast.hk/showthread.php?tid=337810
Tutorial about ORM system: https://sampforum.blast.hk/showthread.php?pid=2682198#pid2682198

Wiki for R33+: https://sampwiki.blast.hk/wiki/MySQL/R33

2 examples of using R34 for register/login system with both cache (threaded queries) and ORM: https://sa-mp-mysql-plugin.******cod...le_scripts.rar
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://github.com/pBlueG/SA-MP-MySQL/releases

There are many changes, threaded queries and ORM system. Non-threaded queries were added again but it's not exactly the same; however, I recommend you to use threaded queries.

Tutorial about threaded queries: https://sampforum.blast.hk/showthread.php?tid=337810
Tutorial about ORM system: https://sampforum.blast.hk/showthread.php?pid=2682198#pid2682198

Wiki for R33+: https://sampwiki.blast.hk/wiki/MySQL/R33

2 examples of using R34 for register/login system with both cache (threaded queries) and ORM: https://sa-mp-mysql-plugin.******cod...le_scripts.rar
Are you familiar with this plugin? I read all the tutorials, but I got a little confused. I tried to replace the queries using the info from there, but I messed the things up. I would like if you could explain me for two types of queryes what changes i have to do and also what does each mean. Because I read the both tutorials you gave me, I think I combined some info and now I don't know which one to use and how.
I want to use cache in my script (I think is better and easier than orm), so, can you explain me this?

Here is my code I want to transforme:
pawn Код:
public OnPlayerConnect(playerid)
{
    new query[300],pname[25],string[300],query2[300], savingstring[20]; //second,minute,year,hour,day, month,query1[300],ip[16];
    GetPlayerName(playerid,pname,24);
    format(query, sizeof(query), "SELECT * FROM users WHERE name = '%s' LIMIT 1", pname); // Here I need help
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(rows==1)
    {
        format(query2,sizeof(query2),"SELECT banned FROM users WHERE name='%s'",pname); // And here
        mysql_query(query2);
        mysql_store_result();
        while(mysql_fetch_row(query,"|"))
        {
        mysql_fetch_field("banned",savingstring);
        PlayerInfo[playerid][pBanned]=strval(savingstring);
        }
        if(PlayerInfo[playerid][pBanned]==0)
        {
        format(string,sizeof(string),"Welcome back, {5E9ACC}%s!\n\n{FFFFFF}Please enter your password below to login to your account.",pname);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Account Login",string,"Login","Quit");
        }
        else if(PlayerInfo[playerid][pBanned]==1)
        {
        MySQL_CheckBan(playerid); // stock function - I will take care of that after I understand how to use this
        }
// There is something more here, not important.
And can you have a look at this also:
pawn Код:
stock MySQL_login(playerid)
{
    new query[500],pname[24],savingstring[100],string[500],mon,score,day, month, year, second, minute, hour,query1[500],ip[20];
    GetPlayerName(playerid,pname,24);
    gettime(hour,minute,second);
    getdate(year,month,day);
    format(query,sizeof(query),"SELECT money, bank, admin, respect, hourson, level, rank, faction, fwarn, \
    fpunish, skin, warned, muted, ajailed, unbanday, unbanmonth, unbanyear, unbanhour, banduration, \
    banreason, banadmin, banperm, civilskin FROM users WHERE name='%s'"
,pname);
    mysql_query(query);
    mysql_store_result();
    ResetPlayerMoney(playerid);
    while(mysql_fetch_row(query,"|"))
    {
        mysql_fetch_field("money",savingstring);
        PlayerInfo[playerid][pMoney]=strval(savingstring);
        mysql_fetch_field("bank",savingstring);
        PlayerInfo[playerid][pBank]=strval(savingstring);
        mysql_fetch_field("admin",savingstring);
        PlayerInfo[playerid][pAdmin]=strval(savingstring);
        mysql_fetch_field("respect",savingstring);
        PlayerInfo[playerid][pRespect]=strval(savingstring);
        mysql_fetch_field("hourson",savingstring);
        PlayerInfo[playerid][pHourson]=strval(savingstring);
        mysql_fetch_field("level",savingstring);
        PlayerInfo[playerid][pLevel]=strval(savingstring);
        mysql_fetch_field("rank",savingstring);
        PlayerInfo[playerid][pRank]=strval(savingstring);
        mysql_fetch_field("faction",savingstring);
        PlayerInfo[playerid][pFaction]=strval(savingstring);
        mysql_fetch_field("fwarn",savingstring);
        PlayerInfo[playerid][pFwarn]=strval(savingstring);
        mysql_fetch_field("fpunish",savingstring);
        PlayerInfo[playerid][pFpunish]=strval(savingstring);
        mysql_fetch_field("skin",savingstring);
        PlayerInfo[playerid][pSkin]=strval(savingstring);
        mysql_fetch_field("warned",savingstring);
        PlayerInfo[playerid][pWarned]=strval(savingstring);
        mysql_fetch_field("muted",savingstring);
        PlayerInfo[playerid][pMuted]=strval(savingstring);
        mysql_fetch_field("ajailed",savingstring);
        PlayerInfo[playerid][pAjailed]=strval(savingstring);
        mysql_fetch_field("unbanday",savingstring);
        PlayerInfo[playerid][pUnbanday]=strval(savingstring);
        mysql_fetch_field("unbanmonth",savingstring);
        PlayerInfo[playerid][pUnbanmonth]=strval(savingstring);
        mysql_fetch_field("unbanyear",savingstring);
        PlayerInfo[playerid][pUnbanyear]=strval(savingstring);
        mysql_fetch_field("unbanhour",savingstring);
        PlayerInfo[playerid][pUnbanhour]=strval(savingstring);
        mysql_fetch_field("banduration",savingstring);
        PlayerInfo[playerid][pBanduration]=strval(savingstring);
        mysql_fetch_field("banreason",savingstring);
        PlayerInfo[playerid][pBanreason]=strval(savingstring);
        mysql_fetch_field("banadmin",savingstring);
        PlayerInfo[playerid][pBanadmin]=strval(savingstring);
        mysql_fetch_field("banperm",savingstring);
        PlayerInfo[playerid][pBanperm]=strval(savingstring);
        mysql_fetch_field("civilskin",savingstring);
        PlayerInfo[playerid][pCivilskin]=strval(savingstring);
    }
    mysql_free_result();
    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Account Login",string,"Login","Quit");
    mon=PlayerInfo[playerid][pMoney];
    score=PlayerInfo[playerid][pLevel];
    GivePlayerMoney(playerid,mon);
    SetPlayerScore(playerid,score);
    if(PlayerInfo[playerid][pFaction]==0) SetPlayerSkin(playerid,PlayerInfo[playerid][pCivilskin]);
    else SetPlayerSkin(playerid,PlayerInfo[playerid][pSkin]);
    PlayerInfo[playerid][pLogged]=1;
    GetPlayerIp(playerid,ip,sizeof(ip));
    format(query1,sizeof(query1),"UPDATE users SET ip = '%s', logged = %d, loginday = %d, loginmonth = %d, loginyear = %d, loginhour = %d, loginmin = %d, loginsec = %d WHERE name = '%s'",ip, PlayerInfo[playerid][pLogged], day, month, year, hour, minute, second, pname);
    mysql_query(query1);
    format(string,sizeof(string),"SERVER: Welcome back, %s!",pname);
    SendClientMessage(playerid,0xFFFFFFFF,string);
}
If I am able to understand how these works, I will manage to do the others by myself. But now I messed all up. I will be very grateful. (also to anyone who explains me).

Thank you anyway!
Reply
#6

pawn Код:
public OnPlayerConnect(playerid)
{
    // reset player's variables on connect..
   
   
    // MySQL holds the connection handle:
    // MySQL = mysql_connect(...);
    new Query[128], pname[21];
    GetPlayerName(playerid, pname, sizeof (pname));
    mysql_format(MySQL, Query, sizeof( Query), "SELECT * FROM users WHERE name = '%e' LIMIT 1", Player_GetName(playerid));
    mysql_tquery(MySQL, Query, "OnPlayerDataLoad", "i", playerid);
   
    // other code that has nothing to do with MySQL..
    return 1;
}

forward OnPlayerDataLoad(playerid);
public OnPlayerDataLoad(playerid)
{
    if (!cache_num_rows())
    {
        // show dialog to register..
    }
    else
    {
        // assign the data from the fields to variables.. as well as the "banned"
       
        if (!(PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "banned")))
        {
            // show dialog to login..
        }
        // else MySQL_CheckBan(playerid);
    }
}
For the stock MySQL_login, you have already selected all the data so no need to do it again. All you have to do at "assign the data from the fields to variables.." part is to use:
pawn Код:
cache_get_field_content(0, field_name, string_to_store, MySQL, sizeof (string_to_store));
for strings (VARCHAR). Edit the field's name and create a variable (string/array) to store the data on it. Change the name from the sizeof too.

For integers:
pawn Код:
PlayerInfo[playerid][some_index_here] = cache_get_field_content_int(0, field_name);
Edit the field's name.

And for floats, almost same as above but instead you've to use:
pawn Код:
PlayerInfo[playerid][some_index_here] = cache_get_field_content_float(0, field_name);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)