I inserted persian string to my table rows in my database, where my columns collection is set to utf8mb4_persian_ci.
But when i want read data from MySql database to php , it doesn't show persian string correctly and just shows ? ? ? ?
I read many article for fix this problem but it didn't work for me I used this code after connecting to database
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$mysqli->set_charset("utf8");
And this code at header of php codes
header("Content-Type: text/html;charset=UTF-8");
And this code at top of html codes
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
But it don't work and I can't see persian string in php pages where it's read from MySql to php
How to fix this problem?
This is the code I used to get this to work properly, since I used all your code, this means your mysql database configuration is incorrect, please recreate your database with the right collation, make sure the table collation is also the same and the field type to be TEXT
Here is the code:
<?php
$mysqli = new mysqli('localhost', 'root', '', 'persian');
$mysqli->set_charset("utf8");
header("Content-Type: text/html;charset=UTF-8");
$mysqli->query("INSERT INTO user SET name='فارسی / پارسی'");
$result = $mysqli->query("SELECT * FROM user");
$result = $result->fetch_object();
echo '<pre dir="ltr">';var_dump($result);echo '</pre>';
echo $result->name;?>
$mysqli->set_charset("utf8");
header("Content-Type: text/html;charset=UTF-8");
instead of $mysqli->set_charset("utf8");
try
$mysqli->set_charset("windows-1256");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With