So over here at BeefyApps are using PostgreSQL instead of MySQL for our WordPress backend. There is this discussion in the WordPress codex which talks about why they do not natively support PostgreSQL out of the box.
However, we have decided that PostgreSQL is the way forward for us so we needed to find a work around. Luckily for us there is a plugin, PostgreSQL for WordPress, which will allow us to do this.
So I followed the steps that were laid out in the Readme.txt that is bundled with the package and I eventually came to run the installation (after the configuration) and I was presented with a blank white screen. Not so lucky after all…
I went through the logs and found:
PHP Fatal error: Cannot redeclare class wpdb |
Which was originating in the class wp-db.php in the wp-includes directory. This was being invoked from the wp-admin/setup-config.php file.
After some searching on the internet I came across some other posts talking about modifying the wp-functions.php file and some others which didn’t really seem appropriate because they would be overwritten with an upgrade. I did find that in the wp-admin/install.php file, there was a reference to wp-db.php as part of the installer. I commented this section out and the installer ran successfully.
I think this problem occurs because before the db.php file can run and eval the class definition inside the wp-db.php file, after it makes it’s replacements for the file, the install.php file has already loaded and processed that class into memory. When we try to redefine the class it throws an error. Anyway it seems to work now.
Tags: PostgreSQL, WordPress
Comments
As a follow up to this, I noticed that the user listing would not show any users either. I looked into the code behind the scenes and found this SQL statement being generated:\\r\\n\\r\\nSELECT DISTINCT(wp_main_users.ID) FROM wp_main_users WHERE 1=1 ORDER BY user_login LIMIT 0, 50\\r\\n\\r\\nDumping that into psql I could see that you need seperate limit and offset clauses in the PostgreSQL statement. Not sure how to fix it long term.
I added this statement into the driver_pgsql.php file to make sure that the order by clauses were included in the select statement. \\r\\n\\r\\n$sql = preg_replace(\\’/(^SELECT DISTINCT\\\\(.+?\\\\))(.+?ORDER BY )(.+?)(\\\\b.+?$)/\\’, \\’$1,$3$2$3$4\\’, $sql);\\r\\n\\r\\nThis is a simple implementation, a more robust one would involve parsing and maintaining a list of the referenced columns in the query so that you could more intelligently handle this.
Mr. Rickard:\\r\\n\\r\\nMy colleagues and I have had issues with other WordPress plugins (specifically Formidable Pro) playing nice with PostgreSQL for WordPress (aka PG4WP) and our PostgreSQl backend. Have you had similar problems with other plugins writing to the database via PG4WP? Thanks for any help and insight!\\r\\n\\r\\ndjm
Is that Moral Orel? nice avatar.\\n\\nWhen working with the code I could definitely understand if there would be problems with many of the plugins that are available as well, simply because many of them may bypass using the WordPress SQL abstraction layer.\\n\\nUnfortunately, my only advice would be to open up the code from the plugin and find where it is making the SQL calls and see what is going wrong. I ended up putting many echo statements in throughout the code when I was debugging so that I could monitor the SQL as the plugin was loading.\\n\\nIf the SQL is being run by the WordPress abstraction layer then you probably will need to do something similar to what I did above where some piece of the conversion code needs to be enhanced to translate some MySQL centric piece of code into something that is readable by PostgresSQL.\\n\\nHope that helps.
Thank you for the reply and debugging suggestion! I think bypass is exactly what\\’s happening. I\\’ll pass this on to the team.\\r\\n\\r\\nThanks for the compliment – D&G bring back so many good memories!\\r\\n\\r\\ndjm
thanks jrickard, your suggestion of removing the reference to wp-db.php in the installer works great
[...] Anschließend ganz normal die Installation fortsetzen (install / upgrade). Quellen: http://wordpress.org/support/topic/wp-31-pg4wp-cannot-redeclare-class-wpdb http://blog.beefyapps.com/2010/12/wordpress-postgresql-trouble-php-fatal-error-cannot-redeclare-clas… [...]
Here is a copy of the driver file:\\r\\n\\r\\nhttp://blog.beefyapps.com/wp-content/uploads/2011/10/driver_pgsql.zip
Thanks for putting this up here. I accidentally deleted the email with the attachment from my phone.
[...] / upgrade). Quellen: http://wordpress.org/support/topic/wp-31-pg4wp-cannot-redeclare-class-wpdb http://blog.beefyapps.com/2010/12/wordpress-postgresql-trouble-php-fatal-error-cannot-redeclare-clas… Tags: [...]
Post a Comment