setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->query("SELECT COUNT(*) FROM boards"); $count = $stmt->fetchColumn(); if ($count > 0) { echo "Database is ready with $count boards\n"; exit(0); } else { echo "Database connected but no boards found, initializing...\n"; $sql = file_get_contents('/var/www/html/sql/create.sql'); $pdo->exec($sql); echo "Database initialized successfully\n"; exit(0); } } catch (PDOException $e) { $attempt++; echo "Attempt $attempt/$maxAttempts: Database not ready yet...\n"; sleep(2); } } echo "Failed to connect to database after $maxAttempts attempts\n"; exit(1);