initial commit
This commit is contained in:
51
db.php
Normal file
51
db.php
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user