I made a little api in php:
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
include_once'conexion.php';
$cliente_usu = $_GET['cliente_usuario'];
$cliente_pass = $_GET['cliente_pass'];
if($_SERVER["REQUEST_METHOD"] == 'GET')
{
$consulta_buscar_usuario = 'SELECT * FROM api_usuario WHERE usuario_nombre = ? AND usuario_contrasena = ?';
$ejecutar_cbu = $pdo->prepare($consulta_buscar_usuario);
$ejecutar_cbu->execute(array($cliente_usu,$cliente_pass));
$data_respuesta = $ejecutar_cbu->fetch();
}
echo json_encode($data_respuesta);
?>
that receives a username and password and returns a json, the problem is that it repeats the information
it should only return what is inside the red box, I use a local apache server and a mysql database with which it connects correctly, to consume the api I use the following line: http://localhost/api/datos.php? client_user=admin&client_pass=admin
It returns both the numeric indices and the associative indices since that is the normal behavior of fetch if no parameters are specified, but if you only want to get the non-numeric fields (associative fields), you can make use of a static constant of
PDO
callFETCH_ASSOC
:That will solve the problem.