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