create_tasks_table.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require_once __DIR__ . '/../config/database.php';
  3. try {
  4. $database = new Database();
  5. $conn = $database->getConnection();
  6. // Read and execute the schema file
  7. $schemaFile = __DIR__ . '/database/tasks_schema.sql';
  8. $schema = file_get_contents($schemaFile);
  9. if ($conn) {
  10. // Split by semicolons and execute each statement
  11. $statements = array_filter(array_map('trim', explode(';', $schema)));
  12. foreach ($statements as $statement) {
  13. if (!empty(trim($statement))) {
  14. echo "Executing: $statement\n";
  15. if ($conn->exec($statement)) {
  16. echo "Success: $statement\n";
  17. } else {
  18. echo "Error: $statement\n";
  19. }
  20. }
  21. }
  22. echo "Tasks table creation completed!\n";
  23. } else {
  24. echo "Database connection failed: " . $conn->errorInfo()[2] . "\n";
  25. }
  26. } catch (Exception $e) {
  27. echo "Error: " . $e->getMessage() . "\n";
  28. }
  29. ?>