WordPress: The Dreaded “Error Establishing Database Connection” message

My site has just been down for more than 24 hours due to a wordpress update, that in its wisdom the plugin developer assumed that the version of MySQL would be an older version, and corrupted the WordPress database that the site uses.

I’ve recovered the site from last nights backup, and thankfully there has been no data loss, but its still a timely reminder as to the importance of regular backups of both files and the database of even a small WordPress site.

Needless to say, panic averted, and automatic plugin updates are now turned off!

Terminal – calculate number of lines of code in a directory

We had an interesting question, can we calculate how many lines of code we have written for an entire project? It turns out this isnt the easiest thing to calculate for a web-project, but we gave it a go. This is the best we have come up with so far for all code we have written to calculate the number of lines of code in all PHP, CSS, JS, HTML and HTM pages.

( find ./ -name '*.php' -print0 -o -name '*.css' -print0 -o -name '*.js' -print0 -o -name '*.html' -print0 -o -name '*.htm' -print0 | xargs -0 cat ) | wc -l

The answer for our particular project was 1500784 lines of code!

If you wanted to do just PHP pages its rather easier:

( find ./ -name '*.php' -print0 | xargs -0 cat ) | wc -l