Jump to content

Storing '," and ` in MYSQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
How can I store '," and ` in MYSQL using PHP? And do I need to do anything special then when receiving the values from the databas?

Thanks :)

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Your trying to store it inside of a row? You probably can just escape it. Usually when I store a bunch of funky characters I would encode it, then decode when I pull it out.

PHP: base64_encode - Manual
PHP: base64_decode - Manual

#3
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
So I should do that on the whole string then? What I'm trying to make sort of a chat and I want to allow those chars too.

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Yea, id store the whole thing encrypted.

If you want to be able to sort by the string you might trying using aes which I mysql supports

MySQL :: MySQL 5.1 Reference Manual :: 11.11.2 Encryption and Compression Functions

#5
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
There's no need for that, the only thing I needs in order is the messages' ID so it's fine. Thanks for the help :thumbup:

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I would just escape it, rather than encode/decode it. Use addslashes() or the mysql_real_escape_string() function.

#7
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
How should I use then? Only add backslashes to the string and then store it?

#8
Guest_Jordan_*

Guest_Jordan_*
  • Guests
If you use either of the functions I mentioned above, it will make this string:
what's going to happen "here"

look like this
what\'s going to happen \"here\"

When inserted into the database, it will become the original string again without the backslashes.

Be careful though, if the server has magic_quotes enabled you will double escape a string if you use those two functions.

#9
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
So I should do like this?

$texttostore = addslashes("what's going to happen \"here\"");


#10
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Yes but when removing slashes it removes all of them. If you intentionally had them say for a local address

C:\\Program Files\Adobe

etc you get the idea.

#11
Guest_Jordan_*

Guest_Jordan_*
  • Guests

Vswe said:

So I should do like this?

$texttostore = addslashes("what's going to happen \"here\"");

Perfect!

#12
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
OK, thanks both of you :thumbup: