Welcome Guest, Not a member yet? Register   Sign In
escape_str Anomaly?
#1

[eluser]Vik[/eluser]
In my database config file, I have:

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

...and in config.php I have:

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

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

Quote: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:

Quote: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:

Quote: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:

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:

Code:
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

[eluser]Ener1[/eluser]
Hey, did you tryed to use htmlentities ?
#3

[eluser]Vik[/eluser]
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. Smile
#4

[eluser]Ener1[/eluser]
Could be great to know, just in case it happeds to anyone else Wink




Theme © iAndrew 2016 - Forum software by © MyBB