1 | <?php |
2 | |
3 | class Bd |
4 | { |
5 | private static ?PDO $pdo = null; |
6 | |
7 | static function pdo(): PDO |
8 | { |
9 | if (self::$pdo === null) { |
10 | |
11 | self::$pdo = new PDO( |
12 | |
13 | "sqlite:srvbd.db", |
14 | |
15 | null, |
16 | |
17 | null, |
18 | |
19 | [PDO::ATTR_PERSISTENT => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION] |
20 | ); |
21 | |
22 | self::$pdo->exec( |
23 | "CREATE TABLE IF NOT EXISTS PASATIEMPO ( |
24 | PAS_ID INTEGER, |
25 | PAS_NOMBRE TEXT NOT NULL, |
26 | CONSTRAINT PAS_PK |
27 | PRIMARY KEY(PAS_ID), |
28 | CONSTRAINT PAS_NOM_UNQ |
29 | UNIQUE(PAS_NOMBRE), |
30 | CONSTRAINT PAS_NOM_NV |
31 | CHECK(LENGTH(PAS_NOMBRE) > 0) |
32 | )" |
33 | ); |
34 | } |
35 | |
36 | return self::$pdo; |
37 | } |
38 | } |
39 | |