WordPress + SQLite

The one thing that really kept me from just installing WordPress and playing around with it was that it required MySQL to run. I don’t need a full-blown RDBMS on my server and I certainly don’t need MySQL (in the past I’ve always used PostgreSQL and in general I like to stick to what I know, especially when it comes to productivity tools). So I was pleased to find out that there’s actually a way to set up WordPress just using PHP5 and SQLite. This is accomplished by a neat plugin called PDO. It’s really easy to install so I wont’t bother with going into any details here.

But there is a catch: The implementation of PDO is slightly broken so when using it you’ll encounter some strange error messages. Problem is that PDO’s database class implements a version of the esc_sql function which is used to sanitize an array of strings for use in SQL queries. Instead of returning an array of the sanitized strings it returns a string which in turn causes the PHP function implode to throw up. The bug and it’s solution are described in detail in the blog post pdo-sqlite bug in wordpress.

Addendum for 07/29/2011:
Sadly, the description of the problem is not available anymore. But I found a summary that describes the fix.

Summary of his fix:

In this file:

wp-content/pdo/db.php

Change this:

function escape($string) {
  return addslashes($string);
}

To this:

function escape( $data ) {
  if ( is_array( $data ) ) {
    foreach ( (array) $data as $k => $v ) {
      if ( is_array( $v ) )
        $data[$k] = $this->escape( $v );
      else
        $data[$k] = $this->_weak_escape( $v );
    }
  } else {
    $data = $this->_weak_escape( $data );
  }
  return $data;
}

Addendum for 04/15/2012:
This fix is no longer necessary with recent versions of WordPress.

This entry was posted in Tools and tagged , , . Bookmark the permalink.

3 Responses to WordPress + SQLite

  1. Jim Williams says:

    In the above definition of escape, where is the function _weak_escape defined?

    Also, in the third line of this definition, why is the (array) $data coercion applied when a successful test for is_array has just been performed?

    • I’m not the author of this fix and have no idea about the intricacies of PHP, so I am not the right person to answer your questions. But it appears that since writing this post the bug has been fixed and not manual editing is necessary anymore to get WordPress running with SQLite as database backend. HTH.

Leave a Reply

Your email address will not be published. Required fields are marked *