mirror of
https://github.com/Tildetel/site.git
synced 2026-01-24 16:10:18 +00:00
Added signup form and revamped phonebook.
This commit is contained in:
41
db.php
Normal file
41
db.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer packages
|
||||
|
||||
// Load environment variables from the .env file
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
$servername = $_ENV['DB_SERVERNAME'];
|
||||
$username = $_ENV['DB_USERNAME'];
|
||||
$password = $_ENV['DB_PASSWORD'];
|
||||
$dbname = $_ENV['DB_NAME'];
|
||||
|
||||
// Create connection
|
||||
$conn = new mysqli($servername, $username, $password);
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Create database if it doesn't exist
|
||||
$sql = "CREATE DATABASE IF NOT EXISTS $dbname";
|
||||
if ($conn->query($sql) === FALSE) {
|
||||
die("Error creating database: " . $conn->error);
|
||||
}
|
||||
|
||||
// Select the database
|
||||
$conn->select_db($dbname);
|
||||
|
||||
// Create the phonebook table if it doesn't exist
|
||||
$sql = "CREATE TABLE IF NOT EXISTS phonebook (
|
||||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
tilde_name VARCHAR(255) NOT NULL,
|
||||
extension VARCHAR(20) NOT NULL,
|
||||
username VARCHAR(255) NOT NULL
|
||||
)";
|
||||
|
||||
if ($conn->query($sql) === FALSE) {
|
||||
die("Error creating table: " . $conn->error);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user