24 lines
781 B
PHP
24 lines
781 B
PHP
<?php
|
|
require_once __DIR__ . '/../../db/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Check if the table already exists
|
|
$stmt = $pdo->query("SHOW TABLES LIKE 'users'");
|
|
if ($stmt->rowCount() == 0) {
|
|
$sql = "CREATE TABLE users (
|
|
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
email VARCHAR(255) NOT NULL UNIQUE,
|
|
password VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)";
|
|
$pdo->exec($sql);
|
|
echo "Table 'users' created successfully." . PHP_EOL;
|
|
} else {
|
|
echo "Table 'users' already exists." . PHP_EOL;
|
|
}
|
|
} catch (PDOException $e) {
|
|
die("Could not connect to the database or create table: " . $e->getMessage());
|
|
}
|