There are hundreds of records in a database that are in windows-1256 charset, I want to read these data and convert them to utf8 then insert them in a new table, to read these data I need to change the MySQL unicode to latin1 and convert the data to utf8. from this link I successfully did this. Now I need to insert these data into database and their charset must be utf8, the problem is $database variable in settings.php have this configuration

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'DB_NAME',
      'username' => 'PASSWORD',
      'password' => 'PASSWORD',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
      'collation' => 'latin1_general_ci',
      'pdo' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES latin1",

and in database/mysql/database.inc line 57 changed to this:

if (!empty($connection_options['collation'])) {
  $this->exec('SET NAMES latin1 COLLATE ' . $connection_options['collation']);

so because of this new database configuration, insertion the converted records (to utf8) doesn't provide the desire result (because MySQL is latin1 now), I need to reset the database configuration to its origin just before inserting the data. how do I can do this?


the only solution I have found so far, is to create another database in utf8 and using external connection move the data into there !!!

1 Answer 1


1) run query ALTER DATABASE DB_NAME DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci on your data base

2) change line

'collation' => 'latin1_general_ci'

in settings.php to

'collation' => 'utf8_general_ci'

and line




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.