PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // Ensure Database exists $pdo->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME); $pdo->exec("USE " . DB_NAME); // Automatic Table Creation: Check if 'users' table exists $tableCheck = $pdo->query("SHOW TABLES LIKE 'users'"); if (!$tableCheck->fetch()) { $sql_file = __DIR__ . '/database.sql'; if (file_exists($sql_file)) { $sql = file_get_contents($sql_file); $pdo->exec($sql); } } } catch (PDOException $e) { die("Database Connection Error: " . $e->getMessage()); } } return $pdo; }