2021-04-26 22:40:34 +02:00
|
|
|
|
<?php
|
|
|
|
|
// TO-DO: Completar
|
|
|
|
|
class DAO {
|
|
|
|
|
//Constants:
|
2021-04-28 21:46:10 +02:00
|
|
|
|
private const _SERVERNAME = BD_HOST;
|
|
|
|
|
private const _USERNAME = BD_USER;
|
|
|
|
|
private const _PASSWORD = BD_PASS;
|
|
|
|
|
private const _BD = BD_NAME;
|
2021-04-26 22:40:34 +02:00
|
|
|
|
|
|
|
|
|
//Atributes:
|
|
|
|
|
public $mysqli;
|
|
|
|
|
|
|
|
|
|
//Constructor:
|
|
|
|
|
public function __construct($bd_name){
|
|
|
|
|
if($bd_name == null) $bd_name = self::_BD;
|
|
|
|
|
try{
|
|
|
|
|
if (!$this->mysqli) {
|
|
|
|
|
$this->mysqli = new mysqli(self::_SERVERNAME, self::_USERNAME,
|
|
|
|
|
self::_PASSWORD, $bd_name);
|
|
|
|
|
}
|
|
|
|
|
// echo "Conexión a la BD, satisfactoria.";
|
|
|
|
|
} catch (Exception $e){
|
|
|
|
|
echo "Error de conexión a la BD: ". mysqli_connect_error();
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ... */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Destructor:
|
|
|
|
|
public function __destruct(){
|
|
|
|
|
$this->mysqli->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Methods:
|
|
|
|
|
}
|
|
|
|
|
?>
|