martes, 19 de mayo de 2020


Conexion.---

class Conexion{

public function conectar(){
    $bd="evaluacion";
$host="mysql:host=localhost;dbname=".$bd;
$usuario="root";
$password="";
$link = new PDO($host,$usuario,$password, array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
return $link;
}

}

-----------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------


  public function nombrefuncion($param){
  $mensaje="";
try {
$conexion=Conexion::conectar();
    $sql="INSERT INTO tabla(campo)
    VALUES (:param);";

    $stmt = $conexion->prepare($sql);
$stmt->bindParam(":param", $param);
$stmt->execute();
        $fila=$stmt->rowCount();     
          $mensaje="Guardo, Proyecto";       
       
} catch(PDOException $e) {

    if ($e->errorInfo[1] == 1062) {
$mensaje="registro duplicado";
      // duplicate entry, do something else
   } else {
      // an error other than duplicate entry occurred
    echo $e->errorInfo[1];
   }
 
}
    return $mensaje;
}
---------------------------------------------------------------

public function listaProyecto(){
       
$stmt = Conexion::conectar()->prepare("query");
$stmt->execute();     
#fetchAll(): Obtiene todas las filas de un conjunto de resultados asociado al objeto PDOStatement.
$array=$stmt->fetchAll(PDO::FETCH_ASSOC);
// cerrar conexion;
$stmt=null;
return $array;       
}

---------------------------------------------------------------------------------------------------------



header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, ,Authorization,Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Allow: GET, POST, OPTIONS, PUT, DELETE");
header('Content-Type: application/json;charset=utf-8');
http_response_code('202');