Tag Archives: mysql_query

[SOLVED] Using mysql_query in WordPress After PHP 5.5

Okay, I am a bit old skool and still use mysql_* and yes I can hear some of you sighing, face palming yourselves and rolling your eyes but I have built thousands of sites over the years, many of you were in diapers when I started and I guess I have been a little slow on the uptake as my code has always been secure and solid, however, yes I realise I need to stop using it because as of PHP 7 it will be removed completely (apparently).

My hope is that this post will help some poor soul, who like me has wasted hours of precious family or personal time trying to resolve the issue.

Annnnnnyway, so, last night I upgraded the PHP version on one of my sites from 5.1 to 5.5 and visited one of the WordPress sites on the server and could see anywhere we have used mysql_query, it was showing the following error:

Warning: mysql_query(): Access denied for user ”@’localhost’ (using password: NO) in/home/website/public_html/wordpress/wp-content/themes/ourtheme/custom/programmes/template1.php on line 4

Warning: mysql_query(): A link to the server could not be established in/home/website/public_html/wordpress/wp-content/themes/ourtheme/custom/programmes/template1.php on line 4
Access denied for user ”@’localhost’ (using password: NO)

I literally spent hours last night trying to find the root cause, I even got the official Cpanel Support team involved thinking it was an issue with PHP on Cpanel or maybe permissions on mysql were fuddled. After a few goes, even the cpanel guy gave up and said it had to be wordpress.

This morning I have come back with a fresh head and searched the google for about 45 minutes and stumbled upon a post (by 1and1 nonetheless…who would have guessed eh?) which suggested to add the following line to your wp-config.php file if you are still using mysql_query() on PHP 5.5

So I added that line to the wp-config.php and all the errors cleared up and the site is rocking on as usual.

You see, WordPress has stopped supporting mysql_* with PHP 5.5, even though PHP 5.5 still supports it, so in essence this was WordPress putting its foot down saying “hey you old dog! stop using non standard ways to connect to the wordpress database”.

Lesson learned and now off to start adapting code to more modern standards such as PDO and MYSQLi.

UPDATED 8/2/2017 – For some of the bigger sites, I will need to use MYSQL SHIM becaseu in some cases its simply not practical to recode everything..