42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
use Hpz937\BillReminder\Database\SQLiteAdapter;
|
|
|
|
// Initialize the SQLite database adapter
|
|
$dbAdapter = new SQLiteAdapter();
|
|
$db = $dbAdapter->connect();
|
|
|
|
// SQL for creating the 'users' table
|
|
$createUsersTable = <<<SQL
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username VARCHAR(255) NOT NULL UNIQUE,
|
|
password VARCHAR(255) NOT NULL,
|
|
email VARCHAR(255) NOT NULL UNIQUE
|
|
);
|
|
SQL;
|
|
|
|
// SQL for creating the 'bills' table
|
|
$createBillsTable = <<<SQL
|
|
CREATE TABLE IF NOT EXISTS bills (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER NOT NULL,
|
|
due_date DATE NOT NULL,
|
|
amount DECIMAL(10, 2) NOT NULL,
|
|
description TEXT,
|
|
is_paid INTEGER DEFAULT 0,
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
);
|
|
SQL;
|
|
|
|
// Execute the SQL queries to create the tables
|
|
try {
|
|
$db->exec($createUsersTable);
|
|
$db->exec($createBillsTable);
|
|
echo "Database setup completed successfully.\n";
|
|
} catch (Exception $e) {
|
|
echo "Error setting up the database: " . $e->getMessage() . "\n";
|
|
}
|