-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconfig.php
More file actions
40 lines (33 loc) · 990 Bytes
/
config.php
File metadata and controls
40 lines (33 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
function connectToDatabase()
{
$db_file = 'empregados.db';
// Attempt to connect to SQLite database
$link = new SQLite3($db_file);
// Create the employees table if it does not exist
$ddl = "
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
address TEXT NOT NULL,
salary INTEGER NOT NULL
);";
if (!$link->exec($ddl)) {
die("ERROR: Could not create table employees.");
}
// Create the employees table if it does not exist
$ddl = "
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);";
if (!$link->exec($ddl)) {
die("ERROR: Could not create table users.");
}
return $link;
}
// Example usage (equivalent to $link in original code)
$link = connectToDatabase();
?>