5]); $db->exec('BEGIN IMMEDIATE'); $applicationId = (int) $db->query('PRAGMA application_id')->fetchColumn(); $version = (int) $db->query('PRAGMA user_version')->fetchColumn(); if ($applicationId === 1163547478 && $version === 1) { $db->exec('COMMIT'); exit(0); } $objects = (int) $db->query("SELECT count(*) FROM sqlite_schema WHERE name NOT GLOB 'sqlite_*'")->fetchColumn(); if ($applicationId !== 0 || $version !== 0 || $objects !== 0) { throw new RuntimeException('Expected a new database or an EzServer PHP database at schema version 1.'); } $schema = file_get_contents(__DIR__ . '/patients.sqlite.sql'); if ($schema === false) { throw new RuntimeException('Could not read the patient schema.'); } $db->exec($schema); $db->exec('PRAGMA application_id = 1163547478'); $db->exec('PRAGMA user_version = 1'); $db->exec('COMMIT'); } catch (Throwable $error) { fwrite(STDERR, 'SQLite initialization failed: ' . $error->getMessage() . PHP_EOL); exit(1); }