SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Backticks used in varchar entries (need fix)

    Hello All,

    I've taken over development of an application recently and noticed the following... For some reason the last developer did a (PHP) str_replace() on text to be entered into a mysql db, replacing any apostrophe (') with a backtick (`) - aka grave accent (used for reserved words in MySQL). I'm guessing he/she did not know about add/stripslashes (much to my dismay) :/. Now when I pull data from the database I get little boxes in the place where the backtick was inserted. I've tried a number of things to fix this and after leaving it alone for a while and working on a script to export the data to an excel spreadsheet I noticed that in the spreadsheet the once was apostrophe/backtick/square box became an apostrophe again. While I could use this technique to clean all the data I would prefer a simpler solution... Any ideas?

    Thanks!!!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i would update the table and change the backticks to apostrophes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did an addslashes(str_replace("’", "'", $rowdata[3]));. The first paameter in str_replace (not able to c&p it here...) was the small box symbol I managed to use c&p to bring it into the code.

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    update thetable
       set thecolumn = replace(thecolumn, '`', '\'')
    FYI: if you're running stripslashes when pulling data from a database, then you're doing something wrong (or the previous programmer did)


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
  •