A. srv / Bd.php

1<?php
2
3class Bd
4{
5
6 private static ?PDO $conexion = null;
7
8 static function getConexion(): PDO
9 {
10 if (self::$conexion === null) {
11
12 self::$conexion = new PDO(
13 // cadena de conexión
14 "sqlite:notificacionespush.db",
15 // usuario
16 null,
17 // contraseña
18 null,
19 // Opciones: conexiones persistentes y lanza excepciones.
20 [PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
21 );
22
23 self::$conexion->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::$conexion;
38 }
39}
40
skip_previous skip_next