Example krakozybr:

In shape

Connect as follows:

$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($mysqli->connect_errno) { echo "НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒΡΡ ΠΊ MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } 

Below is the code that adds the record to the database. utf8_general_ci encoding utf8_general_ci , utf8 script, run from different servers, one result. The ajax request encoding that writes data to variables is also utf8 , the encoding of variables that php operates on is also utf8 . (checked through the function). I output variables to the browser console via ajax from php and they are not displayed as crackers! I do not know what to do.

 $stmt = $mysqli->prepare('INSERT INTO users_1 ( user_id, user_status, user_email, user_pass, user_name, user_surname, user_avatar) VALUES (NULL, "2", ?, ?, ?, ?, "/front/img/users/user.png");'); $stmt->bind_param('ssss', $this->email, $this->pass, $this->name, $this->surname); /* Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ΄Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½Π½ΠΎΠ³ΠΎ выраТСния */ if (!$stmt->execute()) echo "ΠšΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΠ° ΠΈΠΌΠ΅Π½ΠΈ " . mb_detect_encoding($this->name); /* Π—Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠ΅ соСдинСния ΠΈ выраТСния*/ $stmt->close(); 
  • Check how the browser recognizes the output encoding. Maybe this is his glitch. - user207618

2 answers 2

Try to execute the following code immediately after successful connection:

 $mysqli->set_charset('utf8'); 

Or you can still try the following query:

 SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8' 

You can get the current connection encoding with the following code:

 $mysqli->character_set_name() 

    I used this example:

    You must edit the file /etc/mysql/my.cnf

    In the [mysqld] section, add the following lines:

     skip-character-set-client-handshake character-set-server = utf8 init-connect='SET NAMES utf8' collation-server=utf8_general_ci 

    I edited another configuration file: /etc/mysql/mysql.conf.d/mysqld.conf, because specified in the manual is empty. I did not bother with copying.

    http://help.ubuntu.ru/wiki/mysql