Kristaps Gaidulis
Kristaps Gaidulis

Reputation: 104

Mysql query wont work because of special characters

I want to make simple query on my database, but it seems to be problem with latvian symbols in where clause like "ģ,č,ī,ā"

This is my query:

$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));

query works perfect if I put it in phpmyadmin sql box.

I also tried this :

$sql_utf8_latvian_ci = iconv("UTF-8","ISO-8859-1",$sql);
mysqli_query($con1,$sql_utf8_latvian_ci)
or die(mysqli_error($con1));

but it diddnt make any difference, I dont get any errors too.

I think that its because of those symbols, maybe I have missed something?

My php script encoding UTF-8

Upvotes: 0

Views: 392

Answers (1)

Kristaps Gaidulis
Kristaps Gaidulis

Reputation: 104

I had to change the character set to 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));
}

Upvotes: 1

Related Questions