Mysql 由于特殊字符,查询无法正常工作
Mysql query wont work because of special characters
我想对我的数据库进行简单查询,但在 where 子句中的拉脱维亚符号似乎有问题,如 "ģ,č,ī,ā"
这是我的查询:
$sql="insert into c3_zrkac.tests
select *
FROM `web_notikumi_laiki`,`web_notikumi`
WHERE not_id=id_not and not_vieta='Zemgales reģiona Kompetenču attīstības centrā');
mysqli_query($con1,$sql)
or die(mysqli_error($con1));
如果我将查询放在 phpmyadmin sql 框中,查询将完美无缺。
我也试过这个:
$sql_utf8_latvian_ci = iconv("UTF-8","ISO-8859-1",$sql);
mysqli_query($con1,$sql_utf8_latvian_ci)
or die(mysqli_error($con1));
但这没有任何区别,我也没有收到任何错误。
我认为是因为那些符号,也许我错过了什么?
我的 php 脚本编码为 UTF-8
我不得不将字符集更改为 utf-8
/* change character set to utf8 */
if (!mysqli_set_charset($con1,"utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
exit();
} else {
printf("Current character set: %s\n", mysqli_character_set_name($con1));
}
我想对我的数据库进行简单查询,但在 where 子句中的拉脱维亚符号似乎有问题,如 "ģ,č,ī,ā"
这是我的查询:
$sql="insert into c3_zrkac.tests
select *
FROM `web_notikumi_laiki`,`web_notikumi`
WHERE not_id=id_not and not_vieta='Zemgales reģiona Kompetenču attīstības centrā');
mysqli_query($con1,$sql)
or die(mysqli_error($con1));
如果我将查询放在 phpmyadmin sql 框中,查询将完美无缺。
我也试过这个:
$sql_utf8_latvian_ci = iconv("UTF-8","ISO-8859-1",$sql);
mysqli_query($con1,$sql_utf8_latvian_ci)
or die(mysqli_error($con1));
但这没有任何区别,我也没有收到任何错误。
我认为是因为那些符号,也许我错过了什么?
我的 php 脚本编码为 UTF-8
我不得不将字符集更改为 utf-8
/* change character set to utf8 */
if (!mysqli_set_charset($con1,"utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
exit();
} else {
printf("Current character set: %s\n", mysqli_character_set_name($con1));
}