- Samuel's Blog - https://samuelgordonstewart.com -

A workaround for an error with the WordPress Blix 0.9.1 theme under PHP 5.5

At this point in time, this blog is running a theme which it has been running since I first moved it to a WordPress installation in 2005. I have modified the theme a little bit over the years to make the colours more suit tastes and adjust a few functions to work a bit better for my needs. All that said, it is an ancient set of PHP scripts designed to work under an equally ancient version of PHP, and given how much has changed in PHP over the years it could be considered a miracle that the Blix theme still works at all.

Recently I came across a problem which I couldn’t make heads or tails of. Out of the blue, errors started appearing on this blog about failed login attempts where a script on this blog had tried to login to the database as the chief administrative user without a password:

Warning: mysql_query(): Access denied for user ‘root’@’localhost’ (using password: NO) in /home/samuelgo/wp-content/themes/blix/BX_functions.php on line 44
Warning: mysql_query(): A link to the server could not be established in /home/samuelgo/public_html/wp-content/themes/blix/BX_functions.php on line 44
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/samuelgo/public_html/wp-content/themes/blix/BX_functions.php on line 45

I first noticed this problem just after I fixed an issue where the WordPress installation couldn’t login to MySQL and thought it was related and possibly a sign of a very poorly implemented hacking of this blog, but it turned out to be unrelated. The reason WordPress was unable to login to the database was that this site was moved from one server to another and a file with login details was slightly corrupted in the process, and this was easily corrected.

The above errors are related to a function which, on the Archives page [1], shows the number of comments on each post. Previously the “mysql_query” function in the BX_functions file used the login details which WordPress uses, but the “mysql” function has been deprecated as of PHP 5.5 and, while it still works, now seems to need to be explicitly told which login details to use, or it just assumes it should login as “root” without a password (which is possibly the dumbest login details I can think of as it has almost no chance of working on anything but the most insecure of servers). This error, consequently, appears next to each and every post on the archives page, often multiple times. I was able to suppress these errors from displaying until I could get around to figuring out what the problem was, but this still caused the error to be dumped in to an error log many thousands of times per day, causing the error log to grow by hundreds of megabytes each day until I would delete it before it could use up all of the disk space available to this website.

A Google search for the error message shows a lot of blogs running the Blix theme and related themes, but no solution to the problem, so now that I have figured out a workaround, I’ll post it here for the benefit of everyone.

The solution is a tad cumbersome in that it requires the WordPress database username and password to be added to the BX_functions.php file. In reality it is only a workaround as the “mysql” function has been deprecated in favour of other functions and, as such, it will probably exhibit increasingly bizarre behaviour in future version of PHP until support for it is completely removed. This solution works for now, but the only long-term solution is to change to a more modern WordPress theme…I’m still trying to find one that I like as much as Blix.

The solution is to edit your Blix theme’s BX_functions.php file. I would recommend making a backup copy of the file first. This file can usually be found in the /wp-content/themes/blix directory of your website, but if you have a version of Blix which is installed in a different location, then you’ll need to find BX_functions.php in whatever directory the theme is installed in.

You should see a section which looks like this, starting around line 43 (again this may vary if you have a customised version of Blix):

echo "<li>".get_archives_link($url, $text, '');
$comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
$comments_count = mysql_num_rows($comments);
if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' ('.$comments_count.')';
echo "</li>\n";

You will need to add a couple lines as follows below the line starting with “echo” and above the line starting with “$comments = mysql_query”.

mysql_connect("server", "username", "password");
mysql_select_db("databasename");

Naturally you need to change these details so that
“server” is the address of your MySQL server (this is often “localhost”)
“username” is the username of your MySQL user
“password” is the password of your MySQL user
“databasename” is the name of the MySQL database used for your WordPress installation.
Do not remove the quotation marks from around these details.

If you’re not sure of any of these details, you should be able to find them in the wp-config.php file in the root directory of your WordPress installation.

Once you’re done, the above section of the BX_functions.php should look something like this:


echo "<li>".get_archives_link($url, $text, '');
mysql_connect("server", "username", "password");
mysql_select_db("databasename");
$comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
$comments_count = mysql_num_rows($comments);
if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo ' ('.$comments_count.')';
echo "</li>\n";

And the errors should go away.

It’s an annoying issue, but it’s nice to have a solution, even if it is only really a temporary workaround in lieu of upgrading to a theme designed for a modern version of PHP.

Samuel