views:

15

answers:

0

Hi all! I have a very strange problem when retrieving data with php from a mysql table. Basically, two php files with the EXACT same content are given data with different encodings and i dunno why. Here's the code:

$dbhost = 'localhost';
$dbuser = 'myuser';
$dbpass = 'mypass';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'mydb';
mysql_select_db($dbname);
$query="select myfield from mytable limit 1";
$result=mysql_query($query);
$row=mysql_fetch_row($result);
$f = 'log.txt';
$fh=fopen($f,'wb');
fwrite($fh,$row[0]);
fclose($fh);

it's driving me mad since the data looks fine in my db, setting the headers to utf-8 will still display ascii in the second case, setting the charset encoding in html metadata will still display ascii in the second case, the contents of the log file is utf-8 in the first case and ascii in the second. And remember, the two files are absolutely identical, they're even in the same folder.

Please help, many thanks.