prepare( "SELECT COUNT(*) FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = :table AND index_name = :index", ); $statement->execute(["table" => "orders", "index" => "idx_orders_created"]); if ((int) $statement->fetchColumn() > 0) { return; } $pdo->exec("ALTER TABLE orders ADD INDEX idx_orders_created (created_at)"); };