1

Unable to fetch characters as in MySql database below is the table.

    Table1      
+-------------------------------+   
|   APH |   ID0                 |
+-------------------------------+   
|   A   |   Costa Rican Colón   |
|   B   |   Icelandic Króna     |
|   C   |   Somali Shilling     |
|   D   |   Nicaraguan Córdoba  |
+-------------------------------+   

when i get the from db by using PDO in php then the above character shown like this

Costa Rican Col�n

what should i do?

User97798
  • 634
  • 1
  • 5
  • 24
  • 3
    Possible duplicate of [How to support UTF-8 completely in a web application](http://stackoverflow.com/questions/279170/how-to-support-utf-8-completely-in-a-web-application) – cmorrissey Aug 08 '16 at 13:12
  • You need to set the correct character set when creating the database table (UTF-8 is recommended to support a wide range of accented characters). Then see the link above for how to set this in your php code too. Everything needs to be singing from same hymnsheet! – Simon Woolf Aug 08 '16 at 13:14

2 Answers2

2

After fetching from mysql you need to use htmlentities like below in PHP

$str = htmlentities('Costa Rican Colón');
echo $str;exit;
0

When you are fetch data then using this function for character function.

function charConversion($string, $to = "HTML-ENTITIES", $from = 'UTF-8,ASCII,ISO-8859-9,ISO-8859-1') {
    $str = mb_convert_encoding($string, $to, $from);
    $str = stripslashes($str);
    if (empty($str)) {
        return $string;
    }
    return $str;
}
Rax Shah
  • 531
  • 5
  • 18