MySQL data contains special characters, such as š and ć, but they are displayed as '?' on the web page. What for?

I am trying to get a row from a table that contains a value Boris Borenović.
Returns instead Boris Borenovi?.

There is a set of settings in my database and MySQL table utf8_unicode_ci.

My PHP page that displays data from a table that contains the following header: <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />. I also tried with charset=utf-8, but it still doesn't work.

The Sql command used to query data from a table SELECT * FROM contact, so there is nothing special, just a boring simple query. I tried with SELECT * FROM contact COLLATE Latin1_General_CI, but this request could not be completed.

How do I make it work? Thank you

+3
source share
5 answers
<?php

  $mysql_host = "localhost";

  $mysql_db = "database";
  $mysql_user = "username";
  $mysql_pass = "password";

  $mysql_character = "latin1";
  $mysql_collate = "latin1_bin";

  $db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
  if(!$db) echo "Cannot connect to the database!";

  mysql_select_db($mysql_db);
  mysql_query("ALTER DATABASE `".$mysql_db."` DEFAULT CHARACTER SET '".$mysql_character."' COLLATE '".$mysql_collate."'");
  $query = mysql_query("SHOW TABLES");
  while($row = mysql_fetch_array($query)) {
    $table = $row[0];
    mysql_query("ALTER TABLE `".$table."` DEFAULT CHARACTER SET '".$mysql_character."' COLLATE '".$mysql_collate."'");

    $query2 = mysql_query("SHOW columns FROM `".$table."`");
    while($row = mysql_fetch_array($query2)) {
      $column = $row[0];
      $type = $row[1];
      $null = $row[2];
      if($null == "YES") $null = "NULL";
      if($null == "NO") $null = "NOT NULL";
      mysql_query("ALTER TABLE `".$table."` CHANGE COLUMN `".$column."` `".$column."` ".$type." CHARACTER SET '".$mysql_character."' COLLATE '".$mysql_collate."' ".$null);
    }
  }

?>
0
source

Here is the answer: cannot insert Russian text into mysql database. You need to configure MySQL so that utf-8

+1
source

? SET NAMES utf8, utf-8, utf-8, select.

+1

. ? , .

? HTTP, , PHP UTF-8 . 3 PHP UTF-8 cheatsheet.

, , Å¡ š, mysql_set_charset utf8 SELECT.

0

:

mysql_query("SET CHARACTER SET 'utf8'");
mysql_query("SET NAMES 'UTF8'");
mysql_query("SET CHARACTER SET_CLIENT='UTF8'");

(mysql_select_db($Database);)
0

Source: https://habr.com/ru/post/1779753/


All Articles