I am trying to get a data from a database through another table, but when I try to get it, it sends me an array with two instances with the same content:
In the sentence it is assumed that it should only take 1 instance, which is the one there is.
Where I call the function:
Conexion::abrir_conexion();
$dni = RepositorioUsuario::obtener_dni(Conexion::obtener_conexion(), $_SESSION['nombre_usuario']);
var_dump($_SESSION['nombre_usuario']);
var_dump($dni);
Get_dni Here I have the function with your query:
public static function obtener_dni($conexion, $nombre){
$dni_x = true;
if (isset($conexion)){
try{
$sql = "SELECT dni FROM usuarios WHERE nombre = :nombre";
$sentencia = $conexion -> prepare($sql);
$sentencia -> bindParam(':nombre', $nombre, PDO::PARAM_STR);
$sentencia -> execute();
$dni_x = $sentencia -> fetchAll();
//Si establezco esta sentencia no se arregla
//$dni_x = $dni_x[0];
}catch(PDOException $ex){
print 'ERROR'.$ex -> getMessage();
}
}
return $dni_x;
}
Here the database will see that there is no other name or similar:
I had been looking for the solution for a while and I realized that I was creating several arrays inside another, the solution I have found is like this: