0

So I've started making a web application and I thought it would be nice to also have a the functionality in it to handle 'special' characters.

So I have looked around to fix this and have tried multiple things to change charset to utf8.

So I have changed my table using ALTER TABLE mytable CONVERT TO CHARACTER SET utf8

This works IF I run the SQL query in the database. But when I run my query using PHP code, it shows as this:

捦べ 裃壎

My PDO connection is like this:

$this->dbopen = new PDO('mysql:host=' . $this->dbhost . ';dbname='. $this->dbname . '', $this->dbuser, $this->dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") ); 

I've also tried:

$this->dbopen = new PDO('mysql:host=' . $this->dbhost . ';dbname='. $this->dbname . ';charset=utf8', $this->dbuser, $this->dbpass); 

My query goes as follows:

$this->query = 'INSERT INTO titles (Title, Description, Image, SoundFile) VALUES (' . $this->title . ', ' . $this->description . ', ' . $this->image . ', ' . $this->sound . ')';

Yet it still shows it like:
捦べ 裃壎 ず愦ひ嶥鄥 ぐい馯キャば

I have no clue how to change this. Any other suggestions?

Sj03rs
  • 937
  • 10
  • 32
  • The problem is likely on the browser side, with the browser sending HTML encoded data, because you haven't told it how to handle encodings. See [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Feb 03 '16 at 16:38
  • @deceze Alright thanks, I now understand how this works, and it works for me too. Yet, why is it that if I insert using SQL query in the database, it shows the characters. But when I insert into the database using PHP code, it shows the encoded format? – Sj03rs Feb 03 '16 at 17:19

0 Answers0