PHP mysql charset utf8 problems [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UTF-8 all the way through
I'm developing some new features on a website that somebody else already developed.
I'm having a problem the charset.
I saw that the database had some tables in utf8 and some in latin1
So I'm trying to convert all the tables in UTF8.
I did it for one table (also the fields of this table now are utf8), but was not successful.
I'm using the normal mysql connect. I have to put any config to say that it must connect with utf8 to the DB? If yes witch one?
In my html I have:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
It looks like some letters works and others display the question mark.
For example it not able to display this ’ that is different of this: '

Try this
<?php
header('Content-Type: text/html; charset=utf-8');
?>
and then in the connection
<?php
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db($argDB, $dbLink);
mysql_query("set names 'utf8'",$dbLink);
?>

Related

PHP PDO -> SQL bad encode of czech language [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 3 years ago.
im not new in php coding and have a problem. I need insert data to sql (czech language encoding).
I wanna input this string: +ěščřžýáíéůú
My DB output is: +ì¹èø¾ýáíéùú
So, im trying this solutions:
1) My config.php has this one:
header('Content-Type: text/html; charset=utf-8');
ini_set("default_charset", 'utf-8');
2) On top of the page is this meta-tags:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
3) When im connecting into db, im using:
#define("DB_Connect_Charset", "utf8");
$dsn = 'mysql:dbname='.DB_Connect_Database.';host='.DB_Connect_Hostname.';charset='.DB_Connect_Charset;
+
$this->pdo = new PDO($dsn, DB_Connect_Username, DB_Connect_Password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES ".DB_Connect_Charset));
Im trying some php functions like: iconv OR mb_convert_encode()
Database has utf8_czech_ci coding, when im trying to change it into windows-1251 or latin.. it doesnt help.
I spend a lot of time on stackoverflow and cannot find a solution about this problem, some problems will be deleted with SET NAMES UTF8.
Problem must be in part when im sending data to SQL, because if im put data manually into sql, im fetching it correctly.
Thank you for your time and help. Have a nice day!
When I'm binding parameters I use utf8_encode function for value. It was a mistake.

Charset is set to UTF-8, but mysqli reports NOT utf8 [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
All danish characters (æøå etc.) are replaced by questionmarks on my page. It's a classic
Everything (host, database, table) is set to utf8_unicode_ci in phpmyadmin
Every column in the table is set to utf8_unicode_ci
My webpage file is made and saved in UTF-8, and has the php header + meta:
header('Content-type: text/html; charset=utf-8');
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Then I run a mysql charset test in php:
var_dump($conn->get_charset());
The result?
["charset"]=> string(6) "latin1" ["collation"]=> string(17) "latin1_swedish_ci"..
(trimmed vardump)
Why? And how can I fix this?
You have to execute this query after connecting to mysql:
SET NAMES 'utf8'

MySQL & PHP special character issue [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I am using MySQL 5.5 version
when i try to insert the ‘ special character in database it is automatically converted into ’ .
i changed the database character set to utf8 & character_set_connection to utf8 but i unable to get the expected result.
how to solve this issue ?
kindly help on this
You need to check how you are sending the data.
If the character set in the database is utf-8, you need to send like that to.
Try to encode the data before, like that:
$sql = "INSERT INTO tablex(field) VALUES('".utf8_encode($mydata)."')";
It is important to make sure that every part of your connection is using utf8, otherwise you will run into problems.
Below we will create a utf8 connection to the database, perform set names which is vitally important and then write using a utf8_encode method.
mysql_connect("host", "user", "pass");
mysql_query("SET character_set_results=utf8");
mysql_set_charset('utf8');
mb_internal_encoding('UTF-8');
mysql_select_db("my_db");
mysql_query("set names 'utf8'");
$sql = "INSERT INTO `table`(`foo`) VALUES('".utf8_encode($bar)."')";

Arabic text output php mysql utf-8 conversion issue

I'm importing data from Oracle database to MySQL tables.
I have set my MySQL table charset as utf8_general_ci and database and table name with field column value set as utf-8 as well.
Now, When I fetch the result, it prints like, which is with ? sign:
مرحبا العال� - 5
I have my utf value in column is مرحبا العالÙ
When I compare this string with Oracle string, it shows proper value - exact copy of Oracle database and there it shows perfect string in Arabic.
I have set my html meta with utf-8 as well
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
If I set mysql query as below, it shows junk characters:
mysql_query("SET NAMES utf8;");
mysql_query("SET CHARACTER_SET utf8;");
Followed everything possible found over stack and other sites, and still getting an error.
Please help !
Did you save the php-file without BOM? If not, try it. Potential issues with the UTF-8 BOM
Further try with 'utf-8' using single quotes and without SET CHARACTER_SET
mysql_query("SET NAMES 'utf8'");
and with charset utf-8 in the html-document header:
header("content-type: text/html; charset=utf-8");
with pdo you should have this
$_dbhandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"));

UTF8 Characters not displayed correctly [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 9 years ago.
In my mysql database i have string with german umlauts (ä, ö, ü).
I query them with php/mysql and when displayed on my website, they show up like this:
�
I have this html in my website:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
edit: i have changed all collations to utf8_unicode_ci but the problem still persists
If you have written html meta tag as charset=UTF-8 and you have set Collation as utf8_unicode_ci character set and its not working then you must use
mysql_set_charset('utf8');
use this where you have made your connection file, like this:-
$link = mysql_connect("localhost","root","");
$db = mysql_select_db('testing');
mysql_set_charset('utf8');

Categories