A
A
Alex2013-12-11 12:30:26
PHP
Alex, 2013-12-11 12:30:26

How to solve the encoding problem when transferring data between MySQL databases?

There is a Mysql database latin1_swedish_ci and each plate is utf8_unicode_ci. Using a PHP script, I take data from it and add it to another database. If, in a new database, put the same encoding or another one, the following comes to the database: ГДавный дизайнер How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Codebaker, 2013-12-11
@b1nary

Try after establishing a connection with each database:
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci'");

V
Vitaly Zheltyakov, 2013-12-11
@VitaZheltyakov

Better yet, switch to PDO:

$database = new PDO('mysql:host=127.0.0.1;dbname=project', "user", "god", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question