the web shows full blank text when the sentence has a special character (í,ú,ó,é,á)in the database column.
The database its in utf8_general_ci and all the columns.
index.php
<?php
require_once 'db.php';
$query = "SELECT * FROM Frases ORDER BY rand() LIMIT 1";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
print(json_encode($row['frase']));
};
?>
db.php
<?php
// Create connection
$con=mysqli_connect("host","user","pass","database");
// Check connection
if (mysqli_connect_error()){
echo "Faild to connect to MySQL: " . mysqli_connect_error();
}
?>
I have tried in different rows of the database to take out and place different special characters, and whenever they are present, and I reload the page, these rows appear empty.
Thank you.
When i try mysqli_set_charset($link, 'utf8');
in the index.php before the SELECT dosent do anything.
And $mysqli->set_charset('utf8');
it crashes the page.
UPDATE: index.php
<?php
require_once 'db.php';
mysqli_set_charset($con,'utf8');
$query = "SELECT * FROM Frases ORDER BY rand() LIMIT 1";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
print(json_encode($row['frase']));
};
?>
db.php had no change
UPDATE 2 Solution: index.php
<?php
require_once 'db.php';
mysqli_set_charset($con,'utf8mb4');
$query = "SELECT * FROM Frases ORDER BY rand() LIMIT 1";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
print($row['frase']);
};
?>