my table char set is utf8 and it's collation is utf8.now i have this code:
$mysqli = new mysqli("localhost", "root", "", "Amoozeshgah");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
}
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
mysql_set_charset('utf8');
if ($stmt = $mysqli->prepare("SELECT About_Title FROM Tbl_About WHERE About_Id=?")) {
$city = 8;
/* bind parameters for markers */
$stmt->bind_param("s", $city);
/* execute query */
$stmt->execute();
/* bind result variables */
$result = $stmt->get_result();
/* fetch value */
while ($myrow = $result->fetch_assoc()) {
// use your $myrow array as you would with any other fetch
printf("%s is in district %s\n", $city, $myrow['About_Title']);
print("shod");
}
but out put is:
Current character set: utf8 8 is in district نتمنتشس shod
what can i do? Edit: i replaced:
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
mysql_set_charset('utf8');
with
$mysqli->set_charset("utf8")
but no difference.
in your php file add the following at the top of your code
Interesting scenario that may help someone else out. No technical details/explanation and instead just a push/clue in the right direction.
The scenario: remote automated creation of a User Account based on a successful/VERIFIED IPN PayPal Transaction. Mysqli Query creates user and usermeta data, but the value of that data contains hidden formatting characters and invalidates usage of that data called in Form processing. Very simple solution without changing/altering any existing DB Tables. Basically this ensures that your data is only ASCII printable characters and even using $mysqli->set_charset("utf8"); is not really that important since you are preparing your data to be processed and inputted "ASCII clean".
When fetching data from database, you do not only get the data correctly, but also need to show it on pages correctly, so try using UTF-8 encoding in your page header:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
That's my problem and solution, thanks to Rohit Kumar Choudhary.
Please replace
mysql_set_charset('utf8');
to$mysqli->set_charset("utf8")
:-)