Charset iso-8859-1 default charset at mysql

116 views
Skip to first unread message

Mario

unread,
Mar 3, 2011, 6:49:34 AM3/3/11
to php-object-generator
Hi everybody!

I had a problem with charsets 'couse mysql charset was utf-8 and the socket
created with mysql_connect at Database::Database() used iso-8859-1 (latin1).

I fixed by adding a new parameter at file configuration.php

$configuration['encoding'] = 'utf8';

and I also changed the code of the Database::Database() method (constructor)
with this code:

private function Database()
{
$databaseName = $GLOBALS['configuration']['db'];
$serverName = $GLOBALS['configuration']['host'];
$databaseUser = $GLOBALS['configuration']['user'];
$databasePassword = $GLOBALS['configuration']['pass'];
$databasePort = $GLOBALS['configuration']['port'];
$this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword);
if ($this->connection)
{
if (!mysql_select_db ($databaseName))
{
throw new Exception('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.');
}
if (!mysql_set_charset($GLOBALS['configuration']['encoding'],$this->connection))
{
throw new Exception('I cannot change the charset at the connection with database "'.$databaseName.'". Please edit configuration.php.');
}
}
else
{
throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.');
}
}


I hope this help someone with the same trouble.

(I know this could be also fixed changing my.cnf but I prefer this way)


Have a nice day.

Yassin CHOUCHANE

unread,
Mar 20, 2013, 4:04:20 PM3/20/13
to php-object...@googlegroups.com
thanks u save me !

that's works for me
Reply all
Reply to author
Forward
0 new messages