utf8-iso Problem

36 views
Skip to first unread message

Yassin CHOUCHANE

unread,
Mar 20, 2013, 4:00:21 PM3/20/13
to php-object...@googlegroups.com
Hello,
i have a little problem :

well i ceate my table with pdo generator, and the programe give me a script to create my datatable :

    CREATE TABLE `relations` (
    `relationsid` int(11) NOT NULL auto_increment,
    `nomrelation` VARCHAR(255) NOT NULL, PRIMARY KEY  (`relationsid`)) ENGINE=MyISAM;


and on my code  i m using this to add datas :



$rel1 = new relations();
$str1 ="rappelé";
$rel1->nomRelation = $str1;
$rel1->saveNew();

ok that's works :

now the problem i have this on my datatables :

rappelé



how fix the iso probléme please


thanks

Mario

unread,
Mar 20, 2013, 7:16:14 PM3/20/13
to php-object-generator
Hello Yassin,

as you guessed you have a charset conflict. It seems your file (the one that has the code is utf8 and the connection is of other type, maybe iso8859-1, latin1 or another one). I recommend you always use utf8 in the whole project, that includes the database charset, the socket with the database, the php files and http headers and the html headers.


For the database connection, use a code like the one below:

-----------------
<html><body><table><tbody><?php
require_once('configuration.php'); //apply the right path to these files
require_once('class.database.php');
$q = Database::Reader("show variables where variable_name like '%char%'", Database::Connect()); while($v =Database::Read($q)){ echo '<tr><th scope="row">'.$v['Variable_name'].'</th><td><pre>'.$v['Value'].'</pre></td></tr>'; }
$q = Database::Reader("show create database ".$configuration['db'], Database::Connect()); while($v =Database::Read($q)){ echo '<tr><th scope="row">'.$v['Database'].'</th><td><pre>'.$v['Create Database'].'</pre></td></tr>'; }
$q = Database::Reader("show tables", Database::Connect());
while($v =Database::Read($q)){
$tablename= $v['Tables_in_'.$configuration['db']];
$q2 = Database::Reader("show create table ".$tablename, Database::Connect());
while($c =Database::Read($q2)){
echo '<tr><th scope="row">'.$c['Table'].'</th><td><pre>'. $c['Create Table'].'</pre></td></tr>';
}
} ?></tbody></table>
</body></html>

--------------------------------------
it will generate an output like this one:

character_set_clientutf8
character_set_connectionutf8
character_set_databaseutf8
character_set_filesystembinary
character_set_resultsutf8
character_set_serverlatin1
character_set_systemutf8

followed by the create table of each table in the database. 

Every character field should use utf8 as encoding charset. The only one that's not mandatory is "character_set_server" as it can be overriden with the code you have found in the other email. Test the code in this one, it might help you to find hardly tracing errors.

We hope you find POG as useful as we do.
Have a nice day!




Reply all
Reply to author
Forward
0 new messages