php mysql results backslashes removed
I have a table with file names and some other information in it. When I run the following query:
select * from `documentinfo` WHERE `num`='40217'
I get the results correctly:
Array
(
[num] => 40217
[datetime] => 2011-09-15 15:22:07
[date] => 2011-09-15
[filename] => C:\redoak\DocumentsIN\Filer\8883894460_3044564210_07334802020001.mp3
)
When I run the query:
QUERY:`filename` REGEXP '^C:\\redoak\\DocumentsIN\\Filer'
I get:
Array
(
[num] => 35910
[datetime] => 2010-12-03 17:34:38
[date] => 2010-12-03
[filename] => c:
edoakDocumentsINFiler8883894460_3043926485_05863748580001.mp3
)
Notice that the results have the \ removed from the folder name.
I used the following php with both to display this:
while ($row = array_change_key_case(mysql_fetch_assoc($webquery), CASE_LOWER))
{
print_r($row);
}
开发者_如何学PythonQuery for any num works just fine. The regexp query works if the pattern does not contain a backslash. If it contains a backslash it works but the data returned from the table is missing it's back slashes. Even though the query finds the correct records. Thank Oak
Is the the problem: The character_set_results Does a regexp query return a different character set results by default then a = query?
I tried the following to change the character set to see what happened:
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'") or die("ERROR SETTING CHAR SET");
echo '<pre>debug: encoding=', mysql_client_encoding(), '</pre>';
$webquery=mysql_query($query);
echo '<pre>debug: encoding=', mysql_client_encoding(), '</pre>';
it always indicates latin1
I used mysql_set_charset('utf8');
and it changed to utf8
but the results did not change.
MySQL interprets a backslash character as an escape character. For backslash in a query use double backslash \\
精彩评论