DatabaseNotFoundException example

$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.';
          $message .= ' You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.';
          throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode()$e);

        case static::DATABASE_NOT_FOUND:
          throw new DatabaseNotFoundException($e->getMessage()$e->getCode()$e);

        case static::ACCESS_DENIED:
          throw new DatabaseAccessDeniedException($e->getMessage()$e->getCode()$e);

        default:
          throw $e;
      }
    }

    // Force MySQL to use the UTF-8 character set. Also set the collation, if a     // certain one has been set; otherwise, MySQL defaults to
$connection_options['pdo'] += [
      \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
      // Convert numeric values to strings when fetching.       \PDO::ATTR_STRINGIFY_FETCHES => TRUE,
    ];

    try {
      $pdo = new PDOConnection('sqlite:' . $connection_options['database'], '', '', $connection_options['pdo']);
    }
    catch (\PDOException $e) {
      if ($e->getCode() == static::DATABASE_NOT_FOUND) {
        throw new DatabaseNotFoundException($e->getMessage()$e->getCode()$e);
      }
      // SQLite doesn't have a distinct error code for access denied, so don't       // deal with that case.       throw $e;
    }

    // Create functions needed by SQLite.     $pdo->sqliteCreateFunction('if', [__CLASS__, 'sqlFunctionIf']);
    $pdo->sqliteCreateFunction('greatest', [__CLASS__, 'sqlFunctionGreatest']);
    $pdo->sqliteCreateFunction('least', [__CLASS__, 'sqlFunctionLeast']);
    $pdo->sqliteCreateFunction('pow', 'pow', 2);
    


    try {
      $pdo = new \PDO($dsn$connection_options['username']$connection_options['password']$connection_options['pdo']);
    }
    catch (\PDOException $e) {
      if (static::getSQLState($e) == static::CONNECTION_FAILURE) {
        if (str_contains($e->getMessage(), 'password authentication failed for user')) {
          throw new DatabaseAccessDeniedException($e->getMessage()$e->getCode()$e);
        }
        elseif (str_contains($e->getMessage(), 'database') && str_contains($e->getMessage(), 'does not exist')) {
          throw new DatabaseNotFoundException($e->getMessage()$e->getCode()$e);
        }
      }
      throw $e;
    }

    return $pdo;
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.