I am making a query select my mysql database to bring the records of the users that I have registered. The query field for the select is the name and the id, in the field name of the table there are records that have characters like "&" or "ë" or "'", reason why you do not return the records that are in the table.
The query is done from an android app.
<?php
header("Content-type: application/json; charset=utf-8");
//Invocar conexion a host de base de datos
require_once 'mysqlLogin.php';
//Variables de busqueda metodo GET
$id=$_GET["id"];
$empresa=$_GET["empresa"];
// Conectarse a y seleccionar una base de datos de MySQL llamada
$mysqli = new mysqli($hostname, $username,$password, $database);
// comprobar si existe algún error
if ($mysqli->connect_errno) {
echo "Error: Fallo al conectarse a MySQL debido a: \n";
echo "Errno: " . $mysqli->connect_errno . "\n";
echo "Error: " . $mysqli->connect_error . "\n";
exit;
}
//enable utf8!
$mysqli -> query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
// Creamos la consulta SQL
$sql = 'SELECT id_empresa, paquete_empresa, categoria_empresa, nombre_empresa from directorio where id_empresa=? and nombre_empresa=?';
// La preparamos
$stmt = $mysqli->prepare($sql);
// bindeamos los datos
$stmt->bind_param('is', $id,$empresa );
// Ejecutamos la consulta
$stmt->execute();
// Recuperamos los datos
$stmt->bind_result($id, $paquete, $categoria, $nombre);
//Declarar arrelgo
$datos=array();
// comprobar si devolvio registros
if ($stmt){
while ($stmt->fetch()) {
//Crear arreglo temporal para agregar valores de las columnas
$tmp = array();
$tmp["id_empresa"] = $id;
$tmp["paquete_empresa"] = $paquete;
$tmp["categoria_empresa"] = $categoria;
$tmp["nombre_empresa"] = $nombre;
//Agregar a arreglo variable temporal
array_push($datos, $tmp);
}
// Liberar resultados
$stmt->close();
//Convertir respuesta a Json
echo json_encode($datos, JSON_UNESCAPED_UNICODE);
}
else{
echo 'No se encontraron resultados';
exit;
}
// Cerrar la conexión
$mysqli->close();
?>
Database: Configuration