2021-03-24 21:35:59 +01:00
|
|
|
|
<?php
|
|
|
|
|
// TO-DO: Completar
|
|
|
|
|
class DAO {
|
2021-04-06 12:00:31 +02:00
|
|
|
|
//Constants:
|
|
|
|
|
private const _SERVERNAME = "localhost";
|
|
|
|
|
private const _USERNAME = "sw";
|
|
|
|
|
private const _PASSWORD = "_admin_";
|
|
|
|
|
//private const _BD = "complucine";
|
|
|
|
|
|
|
|
|
|
//Atributes:
|
2021-03-24 21:35:59 +01:00
|
|
|
|
public $mysqli;
|
2021-04-06 12:00:31 +02:00
|
|
|
|
|
|
|
|
|
//Constructor:
|
|
|
|
|
public function __construct($bd_name){
|
2021-03-24 21:35:59 +01:00
|
|
|
|
try{
|
|
|
|
|
if (!$this->mysqli) {
|
2021-04-06 12:00:31 +02:00
|
|
|
|
$this->mysqli = new mysqli(_SERVERNAME, _USERNAME,
|
|
|
|
|
_PASSWORD, $bd_name);
|
2021-03-24 21:35:59 +01:00
|
|
|
|
}
|
|
|
|
|
// echo "Conexión a la BD, satisfactoria.";
|
|
|
|
|
} catch (Exception $e){
|
|
|
|
|
echo "Error de conexión a la BD: ". mysqli_connect_error();
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ... */
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 12:00:31 +02:00
|
|
|
|
//Destructor:
|
2021-03-24 21:35:59 +01:00
|
|
|
|
public function __destruct(){
|
|
|
|
|
$this->mysqli->close();
|
|
|
|
|
}
|
2021-04-06 12:00:31 +02:00
|
|
|
|
|
|
|
|
|
//Methods:
|
2021-03-24 21:35:59 +01:00
|
|
|
|
}
|
|
|
|
|
?>
|