我有一个基于 Web 的 PHP 电子邮件客户端(圆立方体),我将其安装在 UNIX 服务器上,它立即出现了这个错误:
Fatal error: Undefined class constant 'MYSQL_ATTR_FOUND_ROWS' in /path/to/file.php on line 134
就是这行代码:
$result[PDO::MYSQL_ATTR_FOUND_ROWS] = true;
在我的 Windows 安装上,它本地运行良好,因此我将这两个 PDO 类与以下内容进行了比较:
<?php ReflectionClass::export('PDO');
该MYSQL_ATTR_FOUND_ROWS
属性和其他一些属性在实时 UNIX 服务器上不存在。我通过对未知值进行硬编码快速修补,效果很好,但我不能确定没有更多错误(而且我们无论如何都不想使用破解版本)。
PDO 类肯定已加载,我们实际上需要首先启用它才能使用 MySQL/PDO 选项安装 Roundcube。我猜好像实时服务器的 PDO 类需要更新?我无法直接控制实时服务器,但我可以向负责控制实时服务器的人提供说明。有人能帮我弄清楚必须做什么吗?
以下是统计数据:
本地 Windows Apache 服务器(运行),PHP 版本 5.3.8
PDO 类调试输出:
Class [ <internal:PDO> class PDO ] {
- Constants [86] {
Constant [ integer PARAM_BOOL ] { 5 }
Constant [ integer PARAM_NULL ] { 0 }
Constant [ integer PARAM_INT ] { 1 }
Constant [ integer PARAM_STR ] { 2 }
Constant [ integer PARAM_LOB ] { 3 }
Constant [ integer PARAM_STMT ] { 4 }
Constant [ integer PARAM_INPUT_OUTPUT ] { -2147483648 }
Constant [ integer PARAM_EVT_ALLOC ] { 0 }
Constant [ integer PARAM_EVT_FREE ] { 1 }
Constant [ integer PARAM_EVT_EXEC_PRE ] { 2 }
Constant [ integer PARAM_EVT_EXEC_POST ] { 3 }
Constant [ integer PARAM_EVT_FETCH_PRE ] { 4 }
Constant [ integer PARAM_EVT_FETCH_POST ] { 5 }
Constant [ integer PARAM_EVT_NORMALIZE ] { 6 }
Constant [ integer FETCH_LAZY ] { 1 }
Constant [ integer FETCH_ASSOC ] { 2 }
Constant [ integer FETCH_NUM ] { 3 }
Constant [ integer FETCH_BOTH ] { 4 }
Constant [ integer FETCH_OBJ ] { 5 }
Constant [ integer FETCH_BOUND ] { 6 }
Constant [ integer FETCH_COLUMN ] { 7 }
Constant [ integer FETCH_CLASS ] { 8 }
Constant [ integer FETCH_INTO ] { 9 }
Constant [ integer FETCH_FUNC ] { 10 }
Constant [ integer FETCH_GROUP ] { 65536 }
Constant [ integer FETCH_UNIQUE ] { 196608 }
Constant [ integer FETCH_KEY_PAIR ] { 12 }
Constant [ integer FETCH_CLASSTYPE ] { 262144 }
Constant [ integer FETCH_SERIALIZE ] { 524288 }
Constant [ integer FETCH_PROPS_LATE ] { 1048576 }
Constant [ integer FETCH_NAMED ] { 11 }
Constant [ integer ATTR_AUTOCOMMIT ] { 0 }
Constant [ integer ATTR_PREFETCH ] { 1 }
Constant [ integer ATTR_TIMEOUT ] { 2 }
Constant [ integer ATTR_ERRMODE ] { 3 }
Constant [ integer ATTR_SERVER_VERSION ] { 4 }
Constant [ integer ATTR_CLIENT_VERSION ] { 5 }
Constant [ integer ATTR_SERVER_INFO ] { 6 }
Constant [ integer ATTR_CONNECTION_STATUS ] { 7 }
Constant [ integer ATTR_CASE ] { 8 }
Constant [ integer ATTR_CURSOR_NAME ] { 9 }
Constant [ integer ATTR_CURSOR ] { 10 }
Constant [ integer ATTR_ORACLE_NULLS ] { 11 }
Constant [ integer ATTR_PERSISTENT ] { 12 }
Constant [ integer ATTR_STATEMENT_CLASS ] { 13 }
Constant [ integer ATTR_FETCH_TABLE_NAMES ] { 14 }
Constant [ integer ATTR_FETCH_CATALOG_NAMES ] { 15 }
Constant [ integer ATTR_DRIVER_NAME ] { 16 }
Constant [ integer ATTR_STRINGIFY_FETCHES ] { 17 }
Constant [ integer ATTR_MAX_COLUMN_LEN ] { 18 }
Constant [ integer ATTR_EMULATE_PREPARES ] { 20 }
Constant [ integer ATTR_DEFAULT_FETCH_MODE ] { 19 }
Constant [ integer ERRMODE_SILENT ] { 0 }
Constant [ integer ERRMODE_WARNING ] { 1 }
Constant [ integer ERRMODE_EXCEPTION ] { 2 }
Constant [ integer CASE_NATURAL ] { 0 }
Constant [ integer CASE_LOWER ] { 2 }
Constant [ integer CASE_UPPER ] { 1 }
Constant [ integer NULL_NATURAL ] { 0 }
Constant [ integer NULL_EMPTY_STRING ] { 1 }
Constant [ integer NULL_TO_STRING ] { 2 }
Constant [ string ERR_NONE ] { 00000 }
Constant [ integer FETCH_ORI_NEXT ] { 0 }
Constant [ integer FETCH_ORI_PRIOR ] { 1 }
Constant [ integer FETCH_ORI_FIRST ] { 2 }
Constant [ integer FETCH_ORI_LAST ] { 3 }
Constant [ integer FETCH_ORI_ABS ] { 4 }
Constant [ integer FETCH_ORI_REL ] { 5 }
Constant [ integer CURSOR_FWDONLY ] { 0 }
Constant [ integer CURSOR_SCROLL ] { 1 }
Constant [ integer MYSQL_ATTR_USE_BUFFERED_QUERY ] { 1000 }
Constant [ integer MYSQL_ATTR_LOCAL_INFILE ] { 1001 }
Constant [ integer MYSQL_ATTR_INIT_COMMAND ] { 1002 }
Constant [ integer MYSQL_ATTR_DIRECT_QUERY ] { 1003 }
Constant [ integer MYSQL_ATTR_FOUND_ROWS ] { 1004 }
Constant [ integer MYSQL_ATTR_IGNORE_SPACE ] { 1005 }
Constant [ integer MYSQL_ATTR_SSL_KEY ] { 1006 }
Constant [ integer MYSQL_ATTR_SSL_CERT ] { 1007 }
Constant [ integer MYSQL_ATTR_SSL_CA ] { 1008 }
Constant [ integer MYSQL_ATTR_SSL_CAPATH ] { 1009 }
Constant [ integer MYSQL_ATTR_SSL_CIPHER ] { 1010 }
Constant [ integer ODBC_ATTR_USE_CURSOR_LIBRARY ] { 1000 }
Constant [ integer ODBC_ATTR_ASSUME_UTF8 ] { 1001 }
Constant [ integer ODBC_SQL_USE_IF_NEEDED ] { 0 }
Constant [ integer ODBC_SQL_USE_DRIVER ] { 2 }
Constant [ integer ODBC_SQL_USE_ODBC ] { 1 }
}
- Static properties [0] {
}
- Static methods [1] {
Method [ <internal:PDO> static public method getAvailableDrivers ] {
- Parameters [0] {
}
}
}
- Properties [0] {
}
- Methods [16] {
Method [ <internal:PDO, ctor> public method __construct ] {
- Parameters [4] {
Parameter #0 [ <required> $dsn ]
Parameter #1 [ <required> $username ]
Parameter #2 [ <required> $passwd ]
Parameter #3 [ <optional> $options ]
}
}
Method [ <internal:PDO> public method prepare ] {
- Parameters [2] {
Parameter #0 [ <required> $statment ]
Parameter #1 [ <optional> $options ]
}
}
Method [ <internal:PDO> public method beginTransaction ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method commit ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method rollBack ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method inTransaction ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method setAttribute ] {
- Parameters [2] {
Parameter #0 [ <required> $attribute ]
Parameter #1 [ <required> $value ]
}
}
Method [ <internal:PDO> public method exec ] {
- Parameters [1] {
Parameter #0 [ <required> $query ]
}
}
Method [ <internal:PDO> public method query ] {
}
Method [ <internal:PDO> public method lastInsertId ] {
- Parameters [1] {
Parameter #0 [ <optional> $seqname ]
}
}
Method [ <internal:PDO> public method errorCode ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method errorInfo ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method getAttribute ] {
- Parameters [1] {
Parameter #0 [ <required> $attribute ]
}
}
Method [ <internal:PDO> public method quote ] {
- Parameters [2] {
Parameter #0 [ <required> $string ]
Parameter #1 [ <optional> $paramtype ]
}
}
Method [ <internal:PDO> final public method __wakeup ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> final public method __sleep ] {
- Parameters [0] {
}
}
}
}
实时 UNIX Apache 服务器(不工作),PHP 版本 5.3.18
PDO 类调试输出:
Class [ <internal:PDO> class PDO ] {
- Constants [77] {
Constant [ integer PARAM_BOOL ] { 5 }
Constant [ integer PARAM_NULL ] { 0 }
Constant [ integer PARAM_INT ] { 1 }
Constant [ integer PARAM_STR ] { 2 }
Constant [ integer PARAM_LOB ] { 3 }
Constant [ integer PARAM_STMT ] { 4 }
Constant [ integer PARAM_INPUT_OUTPUT ] { -2147483648 }
Constant [ integer PARAM_EVT_ALLOC ] { 0 }
Constant [ integer PARAM_EVT_FREE ] { 1 }
Constant [ integer PARAM_EVT_EXEC_PRE ] { 2 }
Constant [ integer PARAM_EVT_EXEC_POST ] { 3 }
Constant [ integer PARAM_EVT_FETCH_PRE ] { 4 }
Constant [ integer PARAM_EVT_FETCH_POST ] { 5 }
Constant [ integer PARAM_EVT_NORMALIZE ] { 6 }
Constant [ integer FETCH_LAZY ] { 1 }
Constant [ integer FETCH_ASSOC ] { 2 }
Constant [ integer FETCH_NUM ] { 3 }
Constant [ integer FETCH_BOTH ] { 4 }
Constant [ integer FETCH_OBJ ] { 5 }
Constant [ integer FETCH_BOUND ] { 6 }
Constant [ integer FETCH_COLUMN ] { 7 }
Constant [ integer FETCH_CLASS ] { 8 }
Constant [ integer FETCH_INTO ] { 9 }
Constant [ integer FETCH_FUNC ] { 10 }
Constant [ integer FETCH_GROUP ] { 65536 }
Constant [ integer FETCH_UNIQUE ] { 196608 }
Constant [ integer FETCH_KEY_PAIR ] { 12 }
Constant [ integer FETCH_CLASSTYPE ] { 262144 }
Constant [ integer FETCH_SERIALIZE ] { 524288 }
Constant [ integer FETCH_PROPS_LATE ] { 1048576 }
Constant [ integer FETCH_NAMED ] { 11 }
Constant [ integer ATTR_AUTOCOMMIT ] { 0 }
Constant [ integer ATTR_PREFETCH ] { 1 }
Constant [ integer ATTR_TIMEOUT ] { 2 }
Constant [ integer ATTR_ERRMODE ] { 3 }
Constant [ integer ATTR_SERVER_VERSION ] { 4 }
Constant [ integer ATTR_CLIENT_VERSION ] { 5 }
Constant [ integer ATTR_SERVER_INFO ] { 6 }
Constant [ integer ATTR_CONNECTION_STATUS ] { 7 }
Constant [ integer ATTR_CASE ] { 8 }
Constant [ integer ATTR_CURSOR_NAME ] { 9 }
Constant [ integer ATTR_CURSOR ] { 10 }
Constant [ integer ATTR_ORACLE_NULLS ] { 11 }
Constant [ integer ATTR_PERSISTENT ] { 12 }
Constant [ integer ATTR_STATEMENT_CLASS ] { 13 }
Constant [ integer ATTR_FETCH_TABLE_NAMES ] { 14 }
Constant [ integer ATTR_FETCH_CATALOG_NAMES ] { 15 }
Constant [ integer ATTR_DRIVER_NAME ] { 16 }
Constant [ integer ATTR_STRINGIFY_FETCHES ] { 17 }
Constant [ integer ATTR_MAX_COLUMN_LEN ] { 18 }
Constant [ integer ATTR_EMULATE_PREPARES ] { 20 }
Constant [ integer ATTR_DEFAULT_FETCH_MODE ] { 19 }
Constant [ integer ERRMODE_SILENT ] { 0 }
Constant [ integer ERRMODE_WARNING ] { 1 }
Constant [ integer ERRMODE_EXCEPTION ] { 2 }
Constant [ integer CASE_NATURAL ] { 0 }
Constant [ integer CASE_LOWER ] { 2 }
Constant [ integer CASE_UPPER ] { 1 }
Constant [ integer NULL_NATURAL ] { 0 }
Constant [ integer NULL_EMPTY_STRING ] { 1 }
Constant [ integer NULL_TO_STRING ] { 2 }
Constant [ string ERR_NONE ] { 00000 }
Constant [ integer FETCH_ORI_NEXT ] { 0 }
Constant [ integer FETCH_ORI_PRIOR ] { 1 }
Constant [ integer FETCH_ORI_FIRST ] { 2 }
Constant [ integer FETCH_ORI_LAST ] { 3 }
Constant [ integer FETCH_ORI_ABS ] { 4 }
Constant [ integer FETCH_ORI_REL ] { 5 }
Constant [ integer CURSOR_FWDONLY ] { 0 }
Constant [ integer CURSOR_SCROLL ] { 1 }
Constant [ integer MYSQL_ATTR_USE_BUFFERED_QUERY ] { 1000 }
Constant [ integer MYSQL_ATTR_LOCAL_INFILE ] { 1001 }
Constant [ integer MYSQL_ATTR_INIT_COMMAND ] { 1002 }
Constant [ integer MYSQL_ATTR_READ_DEFAULT_FILE ] { 1003 }
Constant [ integer MYSQL_ATTR_READ_DEFAULT_GROUP ] { 1004 }
Constant [ integer MYSQL_ATTR_MAX_BUFFER_SIZE ] { 1005 }
Constant [ integer MYSQL_ATTR_DIRECT_QUERY ] { 1006 }
}
- Static properties [0] {
}
- Static methods [1] {
Method [ <internal:PDO> static public method getAvailableDrivers ] {
- Parameters [0] {
}
}
}
- Properties [0] {
}
- Methods [16] {
Method [ <internal:PDO, ctor> public method __construct ] {
- Parameters [4] {
Parameter #0 [ <required> $dsn ]
Parameter #1 [ <required> $username ]
Parameter #2 [ <required> $passwd ]
Parameter #3 [ <optional> $options ]
}
}
Method [ <internal:PDO> public method prepare ] {
- Parameters [2] {
Parameter #0 [ <required> $statment ]
Parameter #1 [ <optional> $options ]
}
}
Method [ <internal:PDO> public method beginTransaction ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method commit ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method rollBack ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method inTransaction ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method setAttribute ] {
- Parameters [2] {
Parameter #0 [ <required> $attribute ]
Parameter #1 [ <required> $value ]
}
}
Method [ <internal:PDO> public method exec ] {
- Parameters [1] {
Parameter #0 [ <required> $query ]
}
}
Method [ <internal:PDO> public method query ] {
}
Method [ <internal:PDO> public method lastInsertId ] {
- Parameters [1] {
Parameter #0 [ <optional> $seqname ]
}
}
Method [ <internal:PDO> public method errorCode ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method errorInfo ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> public method getAttribute ] {
- Parameters [1] {
Parameter #0 [ <required> $attribute ]
}
}
Method [ <internal:PDO> public method quote ] {
- Parameters [2] {
Parameter #0 [ <required> $string ]
Parameter #1 [ <optional> $paramtype ]
}
}
Method [ <internal:PDO> final public method __wakeup ] {
- Parameters [0] {
}
}
Method [ <internal:PDO> final public method __sleep ] {
- Parameters [0] {
}
}
}
}
以下是 php.ini 文件的粘贴链接(内容太大,无法添加到此帖子中):第1部分,第2部分
要将这些缺失的属性放入实时服务器的 PDO 库中,我们需要做的最少的事情是什么?实际上,这里到底发生了什么,为什么它们如此不同?
答案1
所以你只是强迫我重建我的 PHP没有 mysqlnd(就像你的构建一样,只使用libmysql 后端) 来验证我的理论。幸运的是,我有一个 Gentoo 安装,可以快速完成!
正如我所料,没有 mysqlnd,就没有任何PDO::MYSQL_*PDO 类中的常量。因此,要使它们到位,您应该使用 mysqlnd:重新编译 PHP,或者获取 pdo_mysqlnd.so(或针对 mysqlnd 构建的 php_mysql.so)扩展并加载它。
Windows PHP 二进制文件似乎是用 mysqlnd 编译的。
顺便说一下,mysqlnd 是 PHP 5.4.0 以来的默认后端。
答案2
缺失的常量被声明在ext/pdo_mysql/pdo_mysql.c
,根据您的系统,可在以下任一模块中使用:
pdo_mysqlnd.so
pdo_mysql.so
当您运行时,php -m
您将能够看到是否实际加载了任何模块;您将寻找该pdo_mysql
模块。
要将模块编译mysqlnd
成 PHP 二进制文件本身:
./config.nice --enable-mysqlnd --with-pdo-mysql=mysqlnd
make && make install