mirror of https://github.com/TildeNIC/site.git
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?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());
|
|
}
|