Dealing with both US alpha and French accentuated characters

I have a need to be able to enter in the same DB field both US characters and French accentuated char as the content could be in FR or US English.
 As is I tried to set my charset to utf-8
and DB field to utf-8 too

tried also before inserting utf8_encode($str) to no avail

here is the result for example I tried a 4 char words with accent on the 4th char
only the three first char are found in the field the last one is gone.
I thought it might be related to my CleanDb() safe insert function but that is not the case, so I have no idea.. any clue?
thanks
LVL 1
array007Asked:
Who is Participating?
 
eZovCommented:
The best is to use example:http://www.vrelo.biz/testutf.php
Here you can see correct reading French accent from utf field.

I suppose you miss correct setting of character set of db connection:
mysql_set_charset('utf8',$link);

<?php
  $link = mysql_connect('mysql3.loosefoot.com', 'experts', 'experts')
or die("Unable to connect to server");

//echo 'Connected successfully';
mysql_select_db('expertsexchange', $link);

mysql_set_charset('utf8',$link);

//$re = mysql_query('SELECT * FROM testutf;')or die(mysql_error());
//while ($r = mysql_fetch_assoc($re)) {var_dump ($r); echo "<br />";};

?>

<html>
<!-- testutf.php
   Copyright (c) 2010 by Zov-Consulting  http://www.zov-consulting.biz/
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<body>
<b>Read Test UTF</b><br/>
<?php
$re = mysql_query('SELECT testutf FROM testutf;',$link)or die(mysql_error());
while ($r = mysql_fetch_assoc($re)) { echo $r['testutf']."<br />";};    
?>
Here is var dump:<br/>
<?php
    $re = mysql_query('SELECT * FROM testutf;')or die(mysql_error());
while ($r = mysql_fetch_assoc($re)) {var_dump ($r); echo "<br />";};
?>
</body>
</html>

Open in new window

0
 
eZovCommented:
Could you post or attach the results? Did you make test entering  values directly to DB?
0
 
array007Author Commented:
There are no results I can attach as it really is as explained
and YES the DB accepts direct insert with the accent
However the resulting output (site page) shows that "diamond" thing instead of the accentuated letter
but the page has a utf-8 charset so what could be wrong?
thanks
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
eZovCommented:
and DDL for table:
CREATE TABLE `testutf` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `testutf` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MYISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
0
 
eZovCommented:
As I do not know which PHP version you use, this is older command to set connection charset:

mysql_query("SET NAMES 'utf8'",$link);

This is actually MySQL coomand.
0
 
array007Author Commented:
Thanks, well explained!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.