Mysql php special character

My table looks like this:

province_id int(11)                  
province_title char(200) utf8_general_ci 
parent int(8) int(2)

I inserted a lot of data directly from phpMyadmin (not from a php page). but when I get this data and show it on the php page, there are problems with special characters.

as -

Québec shows -  Qu bec.

my html header looks like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I think the problem could happen when inserting data. how can i convert this data to phpmyadmin? any help?

+3
source share
4 answers

it looks like you are not using utf-8 everywhere, so your data at some point messed up. depending on what exactly you are doing, you will have to change / add one or more of the following items (most likely, this is the SET CHARSET/ mysql_set_charsetthat you forgot):

  • MySQL utf-8. my.cnf:

    collation_server = utf8_unicode_ci
    character_set_server = utf8
    
  • mysql :

    SET NAMES 'utf8';
    CHARSET 'utf8';
    

    , , php :

    mysql_set_charset('utf8', $conn); // when using the mysql_-functions
    mysqli::set_charset('utf8') // when using mysqli
    
  • UTF-8

    CREATE DATABASE `my_db` DEFAULT CHARACTER SET 'utf8';
    
  • :

    CREATE TABLE `my_table` (
      -- ...
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
  • , , utf-8 :

    header('Content-type: text/html; charset=utf-8');
    

    , , :

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    
  • , , utf-8

    <form accept-charset="utf-8" ...>
    
+4
0

MySQL UTF-8 .

, ,

mysql_query("SET NAMES utf8");   

PDO,

$options = array(
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
); 

$dbh = new PDO($dsn, $username, $password, $options);
0

If it looks fine when you see the data in phpmyadmin, the problem may be with the text associated with the file itself.

Use Eclipse (Edit "Set Encoding) or Notepad ++ (Encoding) to confirm that you have the correct encoding in the file.

0
source

All Articles