PDO::ERRMODE_EXCEPTION, ]); $message .= "MySQL server connection successful.
"; // 2. Create the database if it doesn't exist $pdo_admin->exec("CREATE DATABASE IF NOT EXISTS `".DB_NAME."`"); $message .= "Database `".DB_NAME."` created or already exists.
"; // 3. Now, connect to the specific database using the existing db() function $pdo = db(); $message .= "Database `".DB_NAME."` connection successful.
"; // 4. Execute 001_create_products_table.sql $sql_create = file_get_contents('db/migrations/001_create_products_table.sql'); if ($sql_create === false) { throw new Exception("Could not read migration file: 001_create_products_table.sql"); } $pdo->exec($sql_create); $message .= "`products` table created successfully.
"; // 5. Execute 002_seed_products.sql $sql_seed = file_get_contents('db/migrations/002_seed_products.sql'); if ($sql_seed === false) { throw new Exception("Could not read migration file: 002_seed_products.sql"); } $pdo->exec($sql_seed); $message .= "`products` table seeded with sample data.
"; $message .= "
Installation complete! You can now go to the homepage."; } catch (Exception $e) { http_response_code(500); $message = "An error occurred: " . $e->getMessage(); } ?> Installation
Database Setup