[SOLVED] character set problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

[SOLVED] character set problem

Post by Darhazer »

Hi,
I'm trying to run some export from the command line. The code is direcly copied from Magento's module

Code: Select all

$compilerConfig = dirname(__FILE__) . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = dirname(__FILE__) . '/app/Mage.php';

require_once($mageFilename);
Mage::app();
foreach ($exportIds as $id => $filename) {
		$filepath = dirname(__FILE__) .'/xml_new/' . $filename;
		Mage::register('frozen_export', $export);
		
		$fp = fopen($filepath, 'w');
		$export = Mage::getModel('exporter/export')->load($id);
		$content = Mage::helper('exporter')->getXmlExport($export, 0, $fp);
		unset($export);
		fclose($fp);
		
		Mage::unregister('frozen_export');
		
}
die('DONE' . PHP_EOL);
The problem is that I get ? on the place of any non-latin character.
If I run query from command line mysql, the result is the same, unless I run
SET character_set_results=utf8;
then I see non-latin characters.
The character_set_results is latin1 (as well as character_set_client and character_set_connection) and I can't change them (it seems it's illegal to change them in my.cnf)
So I've tried to add this piece of code to the script:

[syntax]$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$read->query("set character_set_results=utf8");
//$read->query("set character_set_connection=utf8");
//$read->query("set character_set_client=utf8");[/syntax]
(with and without the commented lines respectiely) but still I got ?

How I can configure mysql so character_set_results is always utf8
The strangest thing is, that in magento however, the non-latin characters are shown correctly
Post Reply