- Joomla works fine with international characters
- A Module Extension I wrote for Joomla! displayed funny characters.
- The Joomla! articles were displaying the correct characters for that language set.
- I needed to make my extension read data from a MySQL database and display the caracters as intended with UTF8.
I tried enough extensions and forum solutions, and although these changes would have an effect on the module (such as take away accents and convert to ASCII), they weren't what we were looking for.
The quick solution was to make the script run a MySQL command at the start: Now I need to run this command from within a Joomla! extension using the mysql Joomla! classes, here's how I've used in this script pulling IDs and titles from the a sample table:
$db =& JFactory::getDBO(); $sql_utf8 = "set names 'utf8'"; $db->setQuery( $sql_utf8 ); $temp_result = $db->query(); $sql = 'SELECT '.$modulescancontentsql.' FROM #__content WHERE state=1'; $db->setQuery( $sql ); $rows = $db->loadObjectList(); foreach( $rows as $row ) { $id = $row->id; $title = $row->title; }
- $db =& JFactory::getDBO();
- $sql_utf8 = "set names 'utf8'";
- $db->setQuery( $sql_utf8 );
- $temp_result = $db->query();
- $sql = 'SELECT '.$modulescancontentsql.' FROM #__content WHERE state=1';
- $db->setQuery( $sql );
- $rows = $db->loadObjectList();
- foreach( $rows as $row ) {
- $id = $row->id;
- $title = $row->title;
- }
Cause: Q. Why does this work for Joomla! articles and not for this module? A. Think this is because that module is loaded before... not sure but for some reason the above command set names 'utf8' is obviously not run prior to the module being displayed.