mirror of
https://github.com/TildeNIC/site.git
synced 2026-01-24 12:00:19 +00:00
first commit
This commit is contained in:
47
includes/initdb-template.php
Normal file
47
includes/initdb-template.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// Use the latest PHP version and enable error reporting
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Database credentials
|
||||
$host = 'hostname';
|
||||
$db = 'db_name';
|
||||
$user = 'db_username';
|
||||
$pass = 'db_password';
|
||||
$charset = 'utf8mb4';
|
||||
|
||||
// DSN (Data Source Name)
|
||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
try {
|
||||
// Create a PDO instance (connect to the database)
|
||||
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||
|
||||
// SQL for creating tables
|
||||
// Users table
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;");
|
||||
|
||||
// Domains table with added ip_address column
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS domains (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
domain_name VARCHAR(255) NOT NULL UNIQUE,
|
||||
dns_records TEXT,
|
||||
ip_address VARCHAR(15), -- Added column for IP address
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
) ENGINE=InnoDB;");
|
||||
|
||||
} catch (\PDOException $e) {
|
||||
throw new \PDOException($e->getMessage(), (int)$e->getCode());
|
||||
}
|
||||
Reference in New Issue
Block a user