MySQL php utf-8 format issues

57 Views Asked by At

So here we go,i have this problem first here is my code

$servername = DB_HOSTNAME;
$username = DB_USERNAME;
$password = DB_PASSWORD;
$dbname = DB_DATABASE;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
/*UTF-8 format*/
$conn->set_charset("utf8");

$clean0 = "SET NAMES utf8;";
$clean1 = "UPDATE product_description SET name = REPLACE(name, '$DeleteWord1', '$empty') WHERE name LIKE '%$FindWord1%';";

if ($conn->query($clean0) === TRUE) {
    echo "<h1>Product unwanted names deleted successfully</h1>";
} else {
    echo "Error updating record: " . $conn->error;
}

if ($conn->query($clean1) === TRUE) {
    echo "<h1>Product unwanted names deleted successfully</h1>";
} else {
    echo "Error updating record: " . $conn->error;
}

The code works fine by itself if i don't use Bulgarian letters. but when i use bulgarian letters the code does not want to find $DeleteWord1

when i varp_dump($clean1)

I get

    string 'UPDATE product_description SET name = REPLACE(name,
 'ЧАСОВНРРљ', ' ') WHERE name LIKE '%SHEEN%';' (length=103)

As you guys can see it's not converted in a UTF-8 aparently for some reason and that's why it does not work with bulgarian letters,

BUT! it works with Bulgarian letters in a Local-Host but not on a Live hosting account

Both databases have collation of utf-8_general_ci (localhost & livehost one)

Any ideas how can i fix this?

$conn->set_charset("utf8");

$clean0 = "SET NAMES utf8;";

Both of those were supposed to do that i tried by themselves e.g only charset and only set names,same issue

And 1 more thing,how can i see if it really passes the values like ЧАСОВНР? since when i set the cleaner.php file to <meta charser="utf-8"> it comes out normally.Any ideas?

0

There are 0 best solutions below