Forums / Developer / Help with UTF8 and eZDB:instance problem needed

Help with UTF8 and eZDB:instance problem needed

Author Message

Bojan S

Wednesday 13 February 2008 9:54:19 am

Hi,

I'm developing contribution for eZ Publish ver. 4.0. The problem is displaying of greman chars.
When I use code:

$db =& eZDB::instance();  
$query = "SELECT * FROM ...";
$ResultArray =& $db->arrayQuery( $query );
$out .= $ResultArray[0][$language];

The output is : Französisch.

When i replace the code above with this code:

mysql_connect('localhost', 'admin', '*****');
mysql_select_db('****');
$row = mysql_fetch_array(mysql_query("SELECT * FROM ...")); 
$out .= $row['$language']); 

The output is: Französisch.

Why first example doesn't work?

Thanks,
b_segic

Björn Dieding@xrow.de

Wednesday 13 February 2008 2:29:26 pm

try

var_dump( $ResultArray );

or

$out .= $ResultArray[0]['language'];

Looking for a new job? http://www.xrow.com/xrow-GmbH/Jobs
Looking for hosting? http://hostingezpublish.com
-----------------------------------------------------------------------------
GMT +01:00 Hannover, Germany
Web: http://www.xrow.com/

Piotrek Karaś

Wednesday 13 February 2008 9:54:02 pm

There's too little context, but that's looks like invalid connection encoding was used to input the data or is skipped when connecting. Normally, before you work with UTF8 DB, you should call 'SET NAMES utf8' query (this is done automatically by eZ Publish db libs, I believe). When you establish your own connection and send query, it's most probably latin encoding by default, which is why your data seems fine.

Hint: use PHPMyAdmin, choose any UTF-8-like language and utf8_general_ci collation (just in case) and look at the data.

PS. Also, not sure if those references are needed there...

Good luck!

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Kristof Coomans

Wednesday 13 February 2008 11:21:09 pm

When using eZDB::instance(), there should be no need anymore to do a "SET NAMES ..." because it's done by the mysql database plugin IF your eZ Publish site is correctly configured (in i18n.ini, [CharacterSettings] Charset=utf-8 and in site.ini [DatabaseSettings] Charset= ). In case you're using mysqli, there's a special function used to set the connection's character set: mysqli_set_charset(...). But in either way, it should be automatically done for you when using eZDB::instance().

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

eZ debug

Timing: Jan 20 2025 20:00:45
Script start
Timing: Jan 20 2025 20:00:45
Module start 'content'
Timing: Jan 20 2025 20:00:45
Module end 'content'
Timing: Jan 20 2025 20:00:45
Script end

Main resources:

Total runtime0.0514 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 589.6172180.8125
Module start 'content' 0.00590.0178 770.429798.0547
Module end 'content' 0.02370.0275 868.484474.7031
Script end 0.0512  943.1875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00234.4833120.0002
Check MTime0.00102.0102120.0001
Mysql Total
Database connection0.00081.579810.0008
Mysqli_queries0.00387.345540.0009
Looping result0.00000.027420.0000
Template Total0.027052.510.0270
Template load0.00132.433710.0013
Template processing0.025750.074710.0257
Override
Cache load0.00101.918410.0010
General
dbfile0.022744.2124100.0023
String conversion0.00000.009730.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs