/    Sign up×
Community /Pin to ProfileBookmark

does mysql database accept character ‘\’?

I save a file directory into mysql database, the directory string looks like:
“…my0my1file.txt”

character ‘‘ above is in C or jave meaning, called escape character.

Actually I use C++ to insert the string into mysql database – I guess php has same issue of this.

But when I read the string from database, escape character ‘‘ disappeared, the directory string looks like:

“…my0my1file.txt”

Now I have to change ‘‘ to ‘/’, so the insert string is “…my0/my1/file.txt”, reading string is fine and is the same as inserted.

my question is:
does mysql database accept character ‘‘? why does ‘‘ disappear? have you met same problem in php program?

How to solve the problem? I like using raw character ‘‘ than modified character ‘/’.

Thanks

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 27.2009 — In PHP, in a double-quote string the "" sequence will be interpreted as a single back-slash, so the actual string stored in memory will just have "" for each instance. In SQL, a single "" is an escape character, so to have a literal "" in a SQL string literal you need to escape it with an additional back-slash, just as you do in the PHP double-quoted string.

[i]So[/i], the usual solution is to run your string value through mysql_real_escape_string(), which escapes certain characters, including back-slashes, with a back-slash for use in your SQL.
[code=php]
$myPath = "c:\path\to\file.php";
$sql = "INSERT INTO table_name (path) VALUES('" . mysql_real_escape_string($myPath) . "')";
$result = mysql_query($sql);
[/code]
×

Success!

Help @html20009876 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...