0

我有 2 个具有以下配置的 linux VM:

虚拟机 1:
OS: Redhat Enterprise Linux 5.4
Apache: 2.2.23
PHP: 5.5.3
MySQL: 5.5.28
PHP config: './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--prefix=/usr/local/apache2/php' '--with-config-file-path=/usr/local/apache2/php' '--disable-cgi' '--with-zlib' '--with-gettext' '--with-gdbm' '--with-sqlite3' '--enable-sqlite-utf8' '--with-mysql=/usr/local/mysql/' '--with-pdo-mysql=mysqlnd' '--enable-mbstring' '--enable-calendar' '--with-curl=/usr/lib' '--with-gd' '--with-jpeg-dir=/usr/lib/libjpeg.so' '--with-png-dir=/usr/lib/libpng.so' '--enable-soap' '--enable-bcmath'

虚拟机 2:
OS: Redhat Enterprise Linux 6.4
Apache: 2.4.6
PHP: 5.3.27
MySQL: 5.6.13
PHP config: './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--prefix=/usr/local/apache2/php' '--with-config-file-path=/usr/local/apache2/php' '--disable-cgi' '--with-zlib' '--with-gettext' '--with-gdbm' '--with-sqlite3' '--enable-sqlite-utf8' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-mbstring' '--enable-calendar' '--with-curl=/usr/lib' '--with-gd' '--with-jpeg-dir=/usr/lib/libjpeg.so' '--with-png-dir=/usr/lib/libpng.so' '--enable-soap' '--enable-bcmath' '--with-mysqli=mysqlnd' '--with-pdo-sqlite' '--with-pear' '--enable-ftp' '--with-openssl'

我有一个 php 类,它使用以下代码使用 PDO 连接到 MySQL 数据库:

    try {            
        $this->maindb = new PDO(PDO_MYSQL_HOST_DBNAME, PDO_MYSQL_USER, PDO_MYSQL_PASSWORD, array(PDO::ATTR_PERSISTENT => true));
        $this->maindb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);            
    } catch (PDOException $e) {
        die('Error connecting database: ' . $e->getMessage());
    }

这部分工作正常,数据按预期插入数据库。

奇怪的是,在类的末尾,当我创建另一个类的对象并将$this->maindb对象传递给它的一个方法以写入更多数据时,它失败并'SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user 'team'@'localhost' (using password: YES)'出现错误。

我的问题是,相同的代码在 VM1 上运行良好,而在 VM2 上失败,如上所述。我已经尝试了这些选项:

  • 具有持久和非持久连接。
  • 使用 MySqlroot用户权限。

我不知道是什么导致了这个问题。请帮我解决这个问题。

注意:我更喜欢任何不涉及降级软件包的解决方案。

4

0 回答 0