create_category_groups.php 987 B

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