I am trying to store some Arabic data in a mysql database I have set the html document charset to be \'utf8\'
Weird, It should work!
Try adding these lines after a successful connection to the database:
$mysqli->query("SET NAMES 'utf8'");
$mysqli->query("SET CHARACTER SET utf8");
For example:
$mysqli = @new mysqli('DB_HOST', 'DB_USER', 'DB_PASS', 'DB_NAME');
if($mysqli->connect_errno) die('Connection Error!');
else{
$mysqli->query("SET NAMES 'utf8'");
$mysqli->query("SET CHARACTER SET utf8");
}
And include these META tags in the head section of your php page:
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
save this file in ur website, htdocs folder as "dbh.php, then in include it at the top of your index page by typing <?php include 'dbh.php';?>
and you u are ready to go.
<?php
$conn = mysqli_connect("localhost", "root", "", "database name");
if(!$conn){
die("connection failed: ".mysqli_connect_error());
}else{
$conn->query("SET NAMES 'utf8'");
$conn->query("SET CHARACTER SET utf8");
}
You may try this. It should work
<?php
$conn = mysqli_connect(<host>, <user name>, <password>, <database name>);
if(!$conn){
die("could not connect: ".mysqli_connect_error());
}else{
mysqli_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
}
?>
Browsers will ignore the <meta http-equiv ...>
tag if there is a http header present. Try putting this at the top of your php page:
header("Content-Type: text/html; charset=UTF-8");