0

I am working on PHP PDO and MYSQL database. I was working on localhost xampp but after uploading on live server I got � sign and  sign with text. It's not showing any issue on localhost xampp. Like - This is my text .  I am checking � .

content longtext    utf8_general_ci 

I am using collation utf8_general_ci in PHPMYADMIN. I have tried -

<?php header("Content-Type: text/html; charset=ISO-8859-1");?>

It removes � sign, not  sign.

<?php header("Content-Type: text/html; charset=utf-8");?>

And it removes  not � This my meta -

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

I am using PHP PDO connection like this -

private $dsn = 'mysql:host=' . self::DBHOST . ';dbname=' . self::DBNAME.';utf8';
        public function __construct(){
            try{
                $this->dbConnection = new PDO($this->dsn, self::DBUSER, self::DBPASS);
                $this->dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
                //echo 'Database connected successfully';
            }

Is there any issue on the live server or I am doing any mistakes?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Shiva
  • 81
  • 7
  • 1
    1. check collation in your hosting server mysql db pls. 2. also use `$mysqli -> set_charset("utf8");` (say for mysqli) and use similar for PDO ,such as $conn->exec('SET NAMES utf8'); – Ken Lee Nov 16 '21 at 09:28
  • I am not using MySQLI. I am using PHP PDO. – Shiva Nov 16 '21 at 09:32
  • 1
    so use PDO syntax pls – Ken Lee Nov 16 '21 at 09:34
  • Thank you Ken Lee . I have placed UTF here and it's working cool . `$this->dbConnection = new PDO($this->dsn, self::DBUSER, self::DBPASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));` – Shiva Nov 16 '21 at 09:44
  • 1
    Great to know that you have fixed the problem. Have a nice day ! – Ken Lee Nov 16 '21 at 23:29
  • This might already be answered at [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Isaac Bennetch Nov 18 '21 at 01:43

0 Answers0