Reputation: 5502
I am trying to access a third party database and having the following error:
Warning: mysql_pconnect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
but I am able to access the database through command prompt by using following command:
mysql -uTheUseerNAme -pThePassword DbName -h HostName --skip-secure-auth
Note: here in the above command I am using --skip-secure-auth
to access the database. But now my question is can we do the same thing in php while making connection with database in config.php file?
Upvotes: 2
Views: 6545
Reputation: 656
With newer versions of PHP (5.6) and mysqli drivers, the default for connecting to MySQL server is to use secure authorization (TLS). It appears that when using an older MySQL server, this will fail.
It doesn't seem that there is a way from within PHP to disable the authentication on connection.
The current workaround is to add this to your MySQL server config (typically found in /etc/mysql/my.cnf or /etc/my.cnf).
[mysqld]
skip-secure-auth
This will disable secure auth from the server side, forcing newer clients (case in point newer versions of PHP/mysqli) to skip the secure auth when connecting, effectively replicating the --skip-secure-auth on all connecting clients.
As a possible workaround without changing the MySQL server config, it appears there is a MYSQLI_OPT_SSL_VERIFY_SERVER_CERT option that can be set on the mysqli connection instance via mysqli_options().
mysqli_options($conn, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
Setting this to false should yield the behavior you are looking for, although there are reports that this does not work and in our testing it did not in fact work.
There appears to have been an update which was pushed to PHP 5.6.16 and later which resolves this issue. My guess is that you are running something between PHP 5.6.0 and 5.6.15.
Upvotes: 2