Raised This Month: $ Target: $400
 0% 

Connecting to mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 04-20-2013 , 10:44   Connecting to mysql
Reply With Quote #1

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
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-20-2013 , 11:25   Re: Connecting to mysql
Reply With Quote #2

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 ''.

Last edited by Backstabnoob; 04-20-2013 at 11:27.
Backstabnoob is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 04-20-2013 , 13:12   Re: Connecting to mysql
Reply With Quote #3

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
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness

Last edited by GuskiS; 04-20-2013 at 13:12.
GuskiS is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-20-2013 , 13:19   Re: Connecting to mysql
Reply With Quote #4

Da labi, Guski, tu vel ar pawnu nodarbojies? Oo
Podarok is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 04-20-2013 , 13:55   Re: Connecting to mysql
Reply With Quote #5

Quote:
Originally Posted by Podarok View Post
Da labi, Guski, tu vel ar pawnu nodarbojies? Oo
Loose ends
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 04-20-2013 , 14:03   Re: Connecting to mysql
Reply With Quote #6

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

Last edited by Backstabnoob; 04-20-2013 at 14:03.
Backstabnoob is offline
GuskiS
Veteran Member
Join Date: Aug 2007
Location: Latvia
Old 04-20-2013 , 15:58   Re: Connecting to mysql
Reply With Quote #7

Trolololol, I read it wrong Omg how stupid, thx again.
__________________
Finished mods:
Trouble in Terrorist Town
MurderMod
The Hidden
Cowboys vs Indians
JailBreak Supreme
Survival Madness
GuskiS is offline
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 10:45.


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