i'm making a request to my db.
When i change "Canuelas" to "Cañuelas", the response it's empty, i tried to change the db, table and row collation but no results.
Here it's an image of the empty response:
Here it's the php code i use to the request:
<?php
include "_db.php";
$con = crearConexion();
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$postdata = file_get_contents("php://input");
$request = json_decode($postdata,true);
$action = $request['action'];
if ($action === "get_propiedades") {
$consulta_propiedades = "SELECT * FROM propiedades WHERE quitado = ''";
$result_propiedades = mysqli_query($con, $consulta_propiedades);
$row_container_propiedades = array();
while($row_propiedades = mysqli_fetch_array($result_propiedades)){
array_push($row_container_propiedades, $row_propiedades);
}
$row_container_propiedades = json_encode($row_container_propiedades);
echo $row_container_propiedades;
}else if ($action === "get_filtros") {
$consulta_filtros = "SELECT * FROM filtros";
$result_filtros = mysqli_query($con, $consulta_filtros);
$row_container_filtros = array();
while($row_filtros = mysqli_fetch_array($result_filtros)){
array_push($row_container_filtros, $row_filtros);
}
$row_container_filtros = json_encode($row_container_filtros);
echo $row_container_filtros;
}
$con->close();
?>
Note: The problem it's in "get_filtros". "get_propiedades" it's retrieved correctly.
Sorry for my bad english!
EDIT: The set_charset('utf8mb4');
did the magic, all i needed to do was adding that line to the db connection, here it's the db connection file if someone need it.
<?php
function crearConexion(){
//Datos para la conexión con el servidor
$servidor = "localhost";
$nombreBD = "dbname";
$usuario = "dbuser";
$contrasena = "dbpass";
//Creando la conexión, nuevo objeto mysqli
$conexion = new mysqli($servidor,$usuario,$contrasena,$nombreBD);
$conexion->set_charset('utf8mb4');
//Si sucede algún error la función muere e imprimir el error
if($conexion->connect_error){
die("Error en la conexion : ".$conexion->connect_errno.
"-".$conexion->connect_error);
}
//Si nada sucede retornamos la conexión
return $conexion;
}
?>