Raised This Month: $ Target: $400
 0% 

How to handle the special characters in MySQL with


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wangningyu
Member
Join Date: Dec 2011
Location: China.GuangDong
Old 02-12-2012 , 11:07   How to handle the special characters in MySQL with
Reply With Quote #1

I used the sqlx library,when insert or query the datebase with special characters, like this:

PHP Code:
        formatex(querycharsmax(query), "SELECT * FROM `Happy` WHERE (`Name` = '%s');"name)

        
SQL_ThreadQuery(g_SQLTuple"QuerySelectData"querydata1
when the name = I'm MT, it contain the ' , so it calls falied.

The premise is not replace special characters,how to fix this code with string format ?


bad for my english.
__________________
One Code , One Dream !

Last edited by wangningyu; 02-12-2012 at 11:09.
wangningyu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-12-2012 , 14:45   Re: How to handle the special characters in MySQL with
Reply With Quote #2

Code:
// name = player's name new fixedName[64]; copy(fixedName, charsmax(fixedName), name); replace_all(fixedName, charsmax(fixedName), "'", "''");

Or, you could just use ^"%s^" instead of '%s' since player names cannot contain double quotes.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-13-2012 , 05:52   Re: How to handle the special characters in MySQL with
Reply With Quote #3

You can also use SQL_QuoteString.
__________________
Impossible is Nothing
Sylwester is offline
wangningyu
Member
Join Date: Dec 2011
Location: China.GuangDong
Old 02-13-2012 , 06:56   Re: How to handle the special characters in MySQL with
Reply With Quote #4

Quote:
Originally Posted by Sylwester View Post
You can also use SQL_QuoteString.
Bad message: the greate firewall fix the url.
__________________
One Code , One Dream !
wangningyu is offline
wangningyu
Member
Join Date: Dec 2011
Location: China.GuangDong
Old 02-13-2012 , 06:56   Re: How to handle the special characters in MySQL with
Reply With Quote #5

Quote:
Originally Posted by Exolent[jNr] View Post
Code:
// name = player's name new fixedName[64]; copy(fixedName, charsmax(fixedName), name); replace_all(fixedName, charsmax(fixedName), "'", "''");


Or, you could just use ^"%s^" instead of '%s' since player names cannot contain double quotes.
this means that replace the ' to '' ?

but also falied too.
__________________
One Code , One Dream !
wangningyu is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-13-2012 , 06:59   Re: How to handle the special characters in MySQL with
Reply With Quote #6

Quote:
Originally Posted by wangningyu View Post
Bad message: the greate firewall fix the url.
What?
__________________
Impossible is Nothing
Sylwester is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-13-2012 , 09:27   Re: How to handle the special characters in MySQL with
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
use ^"%s^" instead of '%s' since player names cannot contain double quotes.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
wangningyu
Member
Join Date: Dec 2011
Location: China.GuangDong
Old 02-13-2012 , 10:02   Re: How to handle the special characters in MySQL with
Reply With Quote #8

Thanks !

I used your way to wrote like this:

PHP Code:
        formatex(querycharsmax(query), "SELECT `Password`, `Status` FROM `registersystem` WHERE (`Name` = ^"%s^");"name)

        
SQL_ThreadQuery(g_SQLTuple"QuerySelectData"querydata1
It's successed !

Thanks again.
__________________
One Code , One Dream !
wangningyu 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 12:18.


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