為什麼這兩個 PDO 類別不同(以及如何使它們相同)?

為什麼這兩個 PDO 類別不同(以及如何使它們相同)?

我有一個基於 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] {
      }
    }
  }
}

Live 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 編譯的。

順便說一下,從 PHP 5.4.0 開始,mysqlnd 是預設後端。

答案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

相關內容