ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

escape_str Anomaly?

June 12, 2010 4:00pm

Subscribe [2]
  • #1 / Jun 12, 2010 4:00pm

    Vik

    209 posts

    In my database config file, I have:

    $db['default']['char_set'] = "utf8";
    $db['default']['dbcollat'] = "utf8_general_ci";

    ...and in config.php I have:

    $config['charset'] = "UTF-8";

    I am trying to store the following string to a mySQL table, using an Ajax call:

    Academia-Gate — the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

    The string arrives at my php Ajax handler function looking like this:

    Academia-Gate — the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

    When I try to store it to my mySQL table, the string is stored like this:

    Academia-Gate ??” the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

    I.e. with ??” in place of the long dash near the beginning.

    I have tracked this down to something that happens during the function escape_str, in DB_driver.php. The escape_str function utilizes a call to mysql_real_escape_string.

    The following code:

    $str = 'Academia-Gate — the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project ';
    $str = mysql_real_escape_string($str, $this->conn_id);

    ...changes the contents of $str to:

    Academia-Gate ‚Ä\" the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the ‚ÄúCry Wolf‚Äù Project

    I.e. it replaces >>>‚Äî<<< with >>>‚Ä\”<<<, so that it is then stored incorrectly in the mySQL table.

    How can I correct this?

    Thanks very much in advance to all for any info.

  • #2 / Jun 18, 2010 7:32pm

    Ener1's avatar

    Ener1

    27 posts

    Hey, did you tryed to use htmlentities ?

  • #3 / Jun 18, 2010 7:47pm

    Vik

    209 posts

    Thanks for the suggestion, Ener1.  I fixed this.  It had nothing to do with escape_str per se.  I still don’t know exactly why it happened.  It was some idiosyncrasy in my code.  Something to do with how the $_RESULT array was being handled and how I was using it.  😊

  • #4 / Jun 18, 2010 7:50pm

    Ener1's avatar

    Ener1

    27 posts

    Could be great to know, just in case it happeds to anyone else 😉

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases