I feel something goes wrong when I take values from the database. But i couldn't found the error. I have tried following codes also.
You need to make sure your entire chain from the connection, to the database, to the tables is all UTF8 clean. I have a detailed answer to a similar question here.
But in your case, check the actual MySQL server my.cnf
file. The following would set the whole chain to UTF-8:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
More immediately, look at your code:
mysql_query("set collation_connection='utf8_sinhala_ci'");
$result = mysqli_query($this->connecDB,"SELECT * FROM pageContent");
In one line you are calling mysql_query
and the next you are calling mysqli_query
. But these are conflicting methods that should not be used together. It should simply be mysqli_query
like so:
mysqli_query($this->connecDB, "SET collation_connection='utf8_sinhala_ci'");
$result = mysqli_query($this->connecDB,"SELECT * FROM pageContent");
Note how I am setting mysqli_query($this->connecDB,…
before your SET collation_connection='utf8_sinhala_ci'
. That will send the query on the same connection you are using for $result
. Or perhaps you can try this instead:
mysqli_query($this->connecDB, "SET NAMES 'utf8'");
$result = mysqli_query($this->connecDB, "SELECT * FROM pageContent");