Cannot connect MySQL with PHP scripts

By | June 6, 2013

php-mysql

If you cannot seem to connect to mysql with a PHP script then it might happen due to the PHP scripts under a domain are not able to connect the MySQL server. You might have mentioned the connection strings correctly but still not able to connect mysql through scripts. To sort this error you can do the following steps:

Locate the server’s php.ini.

[[email protected] ~]# php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

Here we are considering the server is a su-exe server. Copy php.ini file to the document of the domain.

 

[[email protected] ~]# cp /usr/local/lib/php.ini /home/test/public_html

Once you have done this go to the document root of the domain and edit the php.ini file as follows:

 

[[email protected] ~]# cd /home/test/public_html

Open the php.ini file and locate the following line:

 

[[email protected] public_html]# vi php.ini

Locate for the line:

[SQL]
sql.safe_mode = On

Now change this flag setting to Off

[SQL]
sql.safe_mode = Off

Save the settings and restart the Apache service on the server.

[[email protected] ~]# /etc/init.d/httpd restart

Through these steps you will be able to connect MySQL with PHP scripts.