未定义 class 常量 'PDO::FETCH_DEFAULT'

Undefined class constant 'PDO::FETCH_DEFAULT'

我正在使用 PHP FluentPDO,此查询适用于本地主机,但不适用于虚拟主机。 PHP 版本为 7.4,FluentPDO:"envms/fluentpdo": "^2.2"

$pdo = new PDO("mysql:dbname={$mysql['db_name']};host={$mysql['host']}", $mysql['user'],
    $mysql['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'", PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC));

$q = new Query($pdo);

$q->from('table')
    ->where(['email' => 'admin@example.com'])
    ->select('id, name, email, password', true)
    ->fetchAll();

错误是:

Undefined class constant 'PDO::FETCH_DEFAULT'

PHP version is 7.4

不再支持此 PHP 版本。如果可以,请升级到有效支持的版本。

PDO::FETCH_DEFAULT 仅在 PHP 8.0.7 之后可用,因此如果您使用的是更早的版本,则此常量将不可用。

FluentPDO 2.2 版应该仍然支持 PHP 7.4,这使得这是 FluentPDO 中的一个错误。已经存在 pull request 来修复此错误。

这个包似乎有配置错误。当前稳定版本声明 PHP/7.1 为最低版本 (code):

"php": ">=7.1",

但是它使用的是 PDO::FETCH_DEFAULT 常量,这需要 PHP/8.0.7 或更高 (source and code):

PDO::FETCH_DEFAULT (int) Specifies that the default fetch mode shall be used. Available as of PHP 8.0.7.

/** @var int */
protected $currentFetchMode = PDO::FETCH_DEFAULT;

您的选择是: