DatabaseAccessDeniedException example

      \PDO::ATTR_EMULATE_PREPARES => TRUE,
      // Convert numeric values to strings when fetching.       \PDO::ATTR_STRINGIFY_FETCHES => TRUE,
    ];

    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;
  }

  
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     // 'utf8mb4_general_ci' (MySQL 5) or 'utf8mb4_0900_ai_ci' (MySQL 8) for     // utf8mb4.     if (!empty($connection_options['collation'])) {
      
Home | Imprint | This part of the site doesn't use cookies.