Untitled
use Drupal\Core\Database\Database; /** * Implements hook_help() to test the second database connection. */ function mymodule_help($route_name, $route_match) { if ($route_name == 'help.page.mymodule') { $connection = Database::getConnection('default', 'wordpress'); try { $result = $connection->query('SHOW TABLES')->fetchAll(); return 'Successfully connected to the WordPress database. Tables: ' . implode(', ', array_map(function($row) { return current((array) $row); }, $result)); } catch (Exception $e) { return 'Failed to connect to the WordPress database: ' . $e->getMessage(); } } }
Leave a Comment