I am trying to change Turkish character to english character but it doesnt change.I want to run query on mysql database.Mysql doesnt accept turkish character for query.So I couldnt run the query.
My SQL query is:
$sql_test="SELECT a.order_id as siparis_no,
a.firstname as isim,
a.lastname as soyisim,
b.name as urun_Adi
FROM zisl8_mijoshop_order a
LEFT JOIN zisl8_mijoshop_order_product b
ON a.order_id=b.order_id
WHERE a.date_added>'$t_bas' and a.date_added < '$t_bit' AND b.name='Genel Bağış'
";
My PHP replace code:
$replace = array('i', 's', 'o', 'c', 'g', 'u', 'I', 'G', 'O', 'C', 'S', 'U');
$search = array('ı', 'ş', 'ö', 'ç', 'ğ', 'ü', 'İ', 'Ğ', 'Ö', 'Ç', 'Ş', 'Ü');
$str='Genel Bağış';
$str=str_replace($search,$replace,$str);
I know there is no problem at PHP codes.But When try to show on page with echo :
string shows like this 'Genel Bağış'. So seem there is no change that I want make.
And MySQL query doesnt work.But When I change the string as manually like this:
$sql_test="SELECT a.order_id as siparis_no,
a.firstname as isim,
a.lastname as soyisim,
b.name as urun_Adi
FROM zisl8_mijoshop_order a
LEFT JOIN zisl8_mijoshop_order_product b
ON a.order_id=b.order_id
WHERE a.date_added>'$t_bas' and a.date_added < '$t_bit' AND b.name='Genel Bagis'
";
Query is working.String of 'Genel Bağış' comes from mysql db.This is for illustrate to my problem.
So where am I doing mistake, please help?
In every PHP output header, specify UTF-8 as the encoding:
header('Content-Type: text/html; charset=utf-8');
mysql_*
$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8', $link);
mysql_* is deprecated
mysqli
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
$mysqli->set_charset("utf8");
PDO
$pdo = new PDO(
'mysql:host=mysql.example.com;dbname=example_db',
"username",
"password",
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
On the MySQL side of things, modifications to the my.ini
file are required as follows:
[client]
default-character-set=UTF-8
[mysql]
default-character-set=UTF-8
[mysqld]
character-set-client-handshake = false #force encoding to uft8
character-set-server=UTF-8
collation-server=UTF-8_general_ci
[mysqld_safe]
default-character-set=UTF-8
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.