DatabaseConnectionRefusedException example

try {
      $pdo = new \PDO($dsn$connection_options['username']$connection_options['password']$connection_options['pdo']);
    }
    catch (\PDOException $e) {
      switch ($e->getCode()) {
        case static::CONNECTION_REFUSED:
          if (isset($connection_options['unix_socket'])) {
            // Show message for socket connection via 'unix_socket' option.             $message = 'Drupal is configured to connect to the database server via a socket, but the socket file could not be found.';
            $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
            throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode()$e);
          }
          if (isset($connection_options['host']) && in_array(strtolower($connection_options['host'])['', 'localhost'], TRUE)) {
            // Show message for socket connection via 'host' option.             $message = 'Drupal was attempting to connect to the database server via a socket, but the socket file could not be found.';
            $message .= ' A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost.';
            $message .= ' To connect via TPC/IP use an IP address (127.0.0.1 for IPv4) instead of "localhost".';
            $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
            throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode()$e);
          }
          // Show message for TCP/IP connection.           $message = 'This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server.';
          
Home | Imprint | This part of the site doesn't use cookies.