1 | <?php |
2 | |
3 | require_once __DIR__ . "/../modelo/Pasatiempo.php"; |
4 | require_once __DIR__ . "/bdCrea.php"; |
5 | require_once __DIR__ . "/pasatiempoConsulta.php"; |
6 | require_once __DIR__ . "/pasatiempoAgrega.php"; |
7 | |
8 | class Bd |
9 | { |
10 | |
11 | private static ?PDO $conexion = null; |
12 | |
13 | static function getConexion(): PDO |
14 | { |
15 | if (self::$conexion === null) { |
16 | |
17 | self::$conexion = new PDO( |
18 | |
19 | "sqlite:srvauno.db", |
20 | |
21 | null, |
22 | |
23 | null, |
24 | |
25 | [PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] |
26 | ); |
27 | |
28 | bdCrea(self::$conexion); |
29 | $pasatiempo = pasatiempoConsulta(); |
30 | if (count($pasatiempo) === 0) { |
31 | $pasatiempo = new Pasatiempo(nombre: "Futbol"); |
32 | pasatiempoAgrega($pasatiempo); |
33 | |
34 | $pasatiempo = new Pasatiempo(nombre: "Videojuegos"); |
35 | pasatiempoAgrega($pasatiempo); |
36 | } |
37 | } |
38 | |
39 | return self::$conexion; |
40 | } |
41 | } |
42 | |