initial commit

This commit is contained in:
Daniel Cortés
2019-12-12 16:05:20 -03:00
commit f480b2942f
13 changed files with 444 additions and 0 deletions

51
db.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
class DB {
private $server = 'localhost';
private $user= 'root';
private $pass= 'ff9800s_a_d';
private $db= 'alumnos';
private $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
private $dsn;
public function __construct()
{
$this->dsn = "mysql:host=".$this->server.";dbname=".$this->db;
}
public function query($query, ...$params)
{
try
{
$pdo = new PDO($this->dsn, $this->user, $this->pass, $this->options);
$stmt = $pdo->prepare($query);
$stmt->execute($params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
}
public function dml($dml, ...$params)
{
try
{
$pdo = new PDO($this->dsn, $this->user, $this->pass, $this->options);
$stmt = $pdo->prepare($dml);
$stmt->execute($params);
return $stmt->rowCount();
}
catch(PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
}
}
?>