Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Storing '," and ` in MYSQL

  1. #1
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Storing '," and ` in MYSQL

    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. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Storing '," and ` in MYSQL

    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

  4. #3
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Storing '," and ` in MYSQL

    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.

  5. #4
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Storing '," and ` in MYSQL

    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

  6. #5
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Storing '," and ` in MYSQL

    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

  7. #6
    Jordan Guest

    Re: Storing '," and ` in MYSQL

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

  8. #7
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Storing '," and ` in MYSQL

    How should I use then? Only add backslashes to the string and then store it?

  9. #8
    Jordan Guest

    Re: Storing '," and ` in MYSQL

    If you use either of the functions I mentioned above, it will make this string:
    Code:
    what's going to happen "here"
    look like this
    Code:
    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.

  10. #9
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Storing '," and ` in MYSQL

    So I should do like this?

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

  11. #10
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Storing '," and ` in MYSQL

    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.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 05-25-2011, 08:03 PM
  2. MySQL "like" string
    By SimonCoder in forum Database & Database Programming
    Replies: 4
    Last Post: 05-03-2011, 01:18 PM
  3. MySQL - checkbox that overlays "sold" png.
    By Julien Duponte in forum Database & Database Programming
    Replies: 1
    Last Post: 04-14-2011, 11:04 PM
  4. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 47
    Last Post: 01-04-2011, 08:37 PM
  5. Storing "unseen" data of a forum
    By Orjan in forum PHP Development
    Replies: 22
    Last Post: 09-26-2008, 01:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts