I have a list of people that I bring from my bd
, I want to go through that list and change each person in my list one of the attributes of the same one that is of type int
as it can be the document of the person and pass that parameter from a int
to a string
.
Personas.php
<?php
class atencion {
public static function get($peticion){
if ($peticion[0] == 'getAll') {
return self::getAll();
}
public static function getAll(){
$sql = "SELECT * FROM persona";
$sentencia = ConexionBD::obtenerInstancia()->obtenerBD()->prepare($sql);
try{
if ($sentencia->execute()) {
$resultado = $sentencia->fetchAll(PDO::FETCH_CLASS);
return $resultado;
}
else {
return null;
}
}catch(PDOException $e){
throw new ExcepcionApi(self::ESTADO_FALLA_DESCONOCIDA, "Falla desconocida". $e->getMessage(), 400);
}
}
public static function post($peticion){
if ($peticion[0] == 'agregar') {
return self::agregar();
} else {
throw new ExcepcionApi(self::ESTADO_URL_INCORRECTA, "Url mal formada", 400);
}
}
public static function agregar(){
$body = file_get_contents('php://input');
$input = json_decode($body);
$array = (array)$input;
$idPersona = $array['idPersona'];
$documento = $array['documento'];
$sql = "INSERT INTO persona (idPersona, documento) VALUES(:idPersona, :documento)";
try{
$pdo = ConexionBD::obtenerInstancia()->obtenerBD();
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':idPersona', $idPersona);
$stmt->bindParam(':documento', $documento);
$stmt->execute();
$pdo = null;
echo '{"notice": {"text": "Persona Agregada"}';
} catch(PDOException $e){
echo '{"error": {"text": '.$e->getMessage(). '}';
}
}
}