AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Connecting to mysql (https://forums.alliedmods.net/showthread.php?t=213894)

GuskiS 04-20-2013 10:44

Connecting to mysql
 
Ok, lets start. I have plugin, which is base for API and it connects to mysql database. Sometimes it shows errors:
PHP Code:

L 04/19/2013 18:21:13Start of error session.
L 04/19/2013 18:21:13Info (map "deathrun_laikiux_rawr") (file "addons/amxmodx/logs/error_20130419.log")
L 04/19/2013 18:21:13: [AMXXDisplaying debug trace (plugin "vip_api.amxx")
L 04/19/2013 18:21:13: [AMXXRun time error 5memory access 
L 04
/19/2013 18:21:13: [AMXX]    [0vip_api.sma::Load_MySql (line 169)
L 04/19/2013 18:21:13: [AMXX]    [1vip_api.sma::Round_Start (line 127)
L 04/19/2013 18:23:28: [AMXXDisplaying debug trace (plugin "vip_api.amxx")
L 04/19/2013 18:23:28: [AMXXRun time error 5memory access 
L 04
/19/2013 18:23:28: [AMXX]    [0vip_api.sma::Load_MySql (line 169)
L 04/19/2013 18:23:28: [AMXX]    [1vip_api.sma::Round_Start (line 127)
L 04/19/2013 20:01:28Start of error session

Line 169 (SQL_ThreadQuery):
PHP Code:

public Load_MySql(id)
{
    if(!
is_user_connected(id))
        return;
    new 
name[32], szTemp[512]
    
get_user_name(idnamecharsmax(name))
    
replace_all(name55"'""'")

    new 
server get_pcvar_num(vip_server);
    new 
Data[2]
    
Data[0] = id

    format
(szTemp,charsmax(szTemp),"SELECT * FROM `vip_users` WHERE (`nick` = '%s' AND `server` = %d)"name,server)
    
SQL_ThreadQuery(g_SqlTuple,"register_client",szTemp,Data,1)


Line 127 (Load_MySql(id)):
PHP Code:

public Round_Start()
{
    for(new 
id 1id <= g_maxplayersid++)
        
Load_MySql(id)


register_logevent("Round_Start", 2, "1=Round_Start")

Whats wrong, what to do, need help :)

Backstabnoob 04-20-2013 11:25

Re: Connecting to mysql
 
Code:
 replace_all(name, 55, "'", "'")

You need to increase the size of name array to 56. Also, your escaping doesn't make sense. You're just basically changing ' to '. If you want to escape single quotes in MySQL, use either \' or ''.

GuskiS 04-20-2013 13:12

Re: Connecting to mysql
 
Thx for help :)
And, actually the code there is replace_all(name, 56, "'", "&# 39") but it's the same. I just did the API, that was the original code from somewhere :D

Podarok 04-20-2013 13:19

Re: Connecting to mysql
 
Da labi, Guski, tu vel ar pawnu nodarbojies? Oo

GuskiS 04-20-2013 13:55

Re: Connecting to mysql
 
Quote:

Originally Posted by Podarok (Post 1936541)
Da labi, Guski, tu vel ar pawnu nodarbojies? Oo

Loose ends

Backstabnoob 04-20-2013 14:03

Re: Connecting to mysql
 
Change the size to 56 here:
Code:
new name[32]
not in replace_all. Leave 55 there.

GuskiS 04-20-2013 15:58

Re: Connecting to mysql
 
Trolololol, I read it wrong :D Omg how stupid, thx again.


All times are GMT -4. The time now is 10:45.

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