This question already has an answer here:
- UTF-8 all the way through 15 answers
I'm trying to get data from mysql database with php and JSON and it's not working because of the collation I've chosen. I'm using these characters : ® ,é, è , ™, É My deafult collation in mysql is: latin1_swedish_ci,and my server default collation is: utf8mb4_unicode_ci. Should I just remove those special characters or what? this the php code:
<?php
require "conn.php";
$sql = "select * from produit";
$result = mysqli_query($conn, $sql); // result contient tous les produits
$response = array(); // on déclare un array
// pour chaque ligne de la table
while ($row = mysqli_fetch_array($result)) {
array_push($response, array("id_produit"=>$row[0] , "nom"=>$row[1], "catégorie"=>$row[2], "description"=>$row[3], "type"=>$row[4], "prix"=>$row[5], "qte_stock"=>$row[6]));
}
echo json_encode(array("server_response"=> $response));
mysqli_close($conn);
?>
show create table produit :
CREATE TABLE `produit` (
`id_produit` int(11) NOT NULL AUTO_INCREMENT,
`nom` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`catégorie` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`description` text COLLATE utf8mb4_unicode_520_ci NOT NULL,
`type` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`prix` int(11) DEFAULT NULL,
`qte_stock` int(11) DEFAULT NULL,
PRIMARY KEY (`id_produit`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
</div>