MySQL PDO login fails for second connection
I have 2 linux VMs with below configuration:
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'
VM 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'
I have a php class which connects to a MySQL database using PDO using the
following code:
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 part works fine, and data gets inserted to the database as expected.
Strangely towards the end of the class, when I create an object of another
class and pass $this->maindb object to on of its functions to write some
more data, It fails with 'SQLSTATE[28000]: Invalid authorization
specification: 1045 Access denied for user 'team'@'localhost' (using
password: YES)' error.
My problem is, the same code works fine on VM1, and fails on VM2 as
described. I have tried these options:
With both persistent and non-persistent connections.
Used MySql root user privileges.
I have no idea what might be causing this problem. Please help me sort
this out.
NOTE: I prefer any solution which doesn't involve downgrading packages.
No comments:
Post a Comment