{"id":3304,"date":"2008-06-24T10:48:32","date_gmt":"2008-06-24T10:48:32","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/pdo-for-wordpress\/"},"modified":"2010-01-14T11:41:12","modified_gmt":"2010-01-14T11:41:12","slug":"pdo-for-wordpress","status":"closed","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/pdo-for-wordpress\/","author":221413,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"2.7.0","stable_tag":"2.7.0","tested":"2.9.2","requires":"2.3.0","requires_php":"","requires_plugins":"","header_name":"PDO For Wordpress","header_author":"Justin Adie","header_description":"","assets_banners_color":"","last_updated":"2010-01-14 11:41:12","external_support_url":"","external_repository_url":"","donate_link":"http:\/\/rathercurious.net","header_plugin_uri":"http:\/\/rathercurious.net","header_author_uri":"http:\/\/rathercurious.net","rating":5,"author_block_rating":0,"active_installs":0,"downloads":29885,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"2"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.0.1","1.0.2","2.0.0","2.1.0","2.2.0","2.3.0","2.4.0","2.5.0","2.6.0","2.6.1","2.7.0","2.8.0"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[153,48507,28201],"plugin_category":[59],"plugin_contributors":[],"plugin_business_model":[],"class_list":["post-3304","plugin","type-plugin","status-closed","hentry","plugin_tags-database","plugin_tags-pdo","plugin_tags-sqlite","plugin_category-utilities-and-tools","plugin_committers-jpadie"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/pdo-for-wordpress.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>Wordpress has for a long time, and for good reasons, been locked into using mysql as its database storage engine.  There is a good discussion of 'why' <a href=\"http:\/\/codex.wordpress.org\/Using_Alternative_Databases#Solutions\/\" title=\"Codex Discussion\">in the codex<\/a><\/p>\n\n<p>But this design choice has ramifications; not least because mysql's implementation of sql is not standard.  Even with the use of the EZSQL abstraction layer bundled with Wordpress, this makes plugging in other databases very difficult.<\/p>\n\n<p>PDO For Wordpress is a step towards eliminating this difficulty.  Think about this 'plugin' in four steps:<\/p>\n\n<ol>\n<li>the basic layer takes all queries and separates out the variables from the language.  It replaces each variable with a placeholder as well as stripping mysql specific 'nasties' like the slash-escaping and backticks.<\/li>\n<li>then a language specific driver steps in and rewrites the query to use its own native constructs or (in the case of SQLite) pushes the query into some special user-defined functions<\/li>\n<li>the basic layer then puts it all back together and runs the query, finally ...<\/li>\n<li>returning the whole thing to the EZSQL abstraction layer so that Wordpress doesn't know that anything has gone awry<\/li>\n<\/ol>\n\n<p>See below\/other notes for details of known limitations<\/p>\n\n<h3>Known Limitations<\/h3>\n\n<ul>\n<li>this plugin requires PHP 5.0 + as it uses PDO.  There is no workaround.<\/li>\n<li>the database schema cannot be upgraded through the WP automatic systems. I am working on this: it is non-trivial<\/li>\n<li>some plugins will not upgrade as they use the WP upgrade functions to upgrade their databases.  Create statements issued through dbdelta() WILL work, however<\/li>\n<li>some plugins will not install\/work as they do use native mysql calls rather than the WP abstraction layer.  This is contrary to WordPress API guidelines.<\/li>\n<\/ul>\n\n<h3>To Do<\/h3>\n\n<ul>\n<li>parameterise the database location to allow people to change the name and the location of the database<\/li>\n<li>write a routine to allow upgrades\/changes to the database schema.  This is not easy as sqlite does not support the alter syntax to the same extent that mysql does.  [We could just fudge this and leave old columns in the table]* examine and consider replacing some of the clunky code in the sqlite engine to use user defined functions in some cases (e.g. dates and if).  <\/li>\n<li>remove some of the clunky debug code<\/li>\n<li>consider adding collation support.<\/li>\n<li>remove inefficiency of object recreation at the end of the post-processing. it should be easier to keep the pdo resultset as an array of objects to start with.<\/li>\n<li>consider using WP's own error handling class  <\/li>\n<li>consider revising the prepare-&gt;execute syntax to a pure query type syntax for certain types of query  <\/li>\n<li>consider altering the directory structure so that the majority of files can sit under the plugins directory and use the auto-updater.  <\/li>\n<li>or write an updater plugin (is that possible if they come from different sources?)<\/li>\n<\/ul>\n\n<h3>Attributions<\/h3>\n\n<p>Early versions of this plugin used a complete replacement for the WP abstraction layer.  Thanks to Ulf Ninow for pointing out the value of inheritance to me and thus hugely simplifying the upkeep of the plugin.<\/p>\n\n<h3>Version Information<\/h3>\n\n<p>version 2.7.0 - 2010 January 13\nchanges in the WP installation code broke this plugin.  Compatibility is now fixed through a rewrite of wp_install\nchanges in 2.8.1 broke some other functionality.  Essentially greater use of mysql &gt;=4.1 functions means that it's a constant game of catch up to rewrite.  Really the WP core team should go back to basics and use pure SQL ANSI syntax (particularly if the rumours about migration to MS SQL are true)\nMove to UDF's in place of a whole bunch of regex work.  this should speed up execution.\nand other minor changes.\nstill have to fix up the debug code.  it's horribly clunky but we need very accurate feedback to debug failing queries...<\/p>\n\n<p>Version 2.6.1 - 2009 June 13\nfix error in Optimize queries - thanks fnumatic\nfix small error in multi-inserts leading to problem with importing from existing wordpress installation\nNB there is still a problem with the regex on multi-inserts, as yet no fix but the error should not manifest except as a small performance decrease<\/p>\n\n<p>Version 2.6.0 - 2009 June 01\ncreate a new query type to handle insert multiples\nfix bug with install routine and sqlite schema changes<\/p>\n\n<p>Version 2.5.0 - 2009 May 04\n[version 2.0.0 + has had a bunch of problems in it (inc 2.4.0).  how these crept in is unknown.]\nfixes inconsistency between string and integer based data comparisons in sqlite<\/p>\n\n<p>Version 2.4.0 - 2009 May 03 \nfix another installation problem linked to query buffering<\/p>\n\n<p>Version 2.3.0 - 2000 May 02\nadded some more checking into the install routine to avoid perms problems\ncleaned up the date handling thanks to Nicholas Schmid.  This will improve permalinks<\/p>\n\n<p>Version 2.2.0 - 2009 April 29\ncreate new tag and recommit because tag 2.1.0 was corrupt<\/p>\n\n<p>Version 2.1.0 - 2009 April 21\nadded global $wpdb to the connect method in PDOEngine.php\nfixed some umask errors<\/p>\n\n<p>Version 2.0.0 - 2009 April 03\noverhaul of the sqlite code to use UDF's in place of regex (for the most part)\noverhaul of the base class to reuse the wpdb class by inheritance<\/p>\n\n<p>Version 1.0.2 - 2008 June 29\nversion control issue.  not all files were committed to svn in 1.0.1<\/p>\n\n<p>Version 1.0.1 - 2008 June 28\nFixed bug where the comments did not display in Manage Comments due to the use of index hints in the mysql sql<\/p>\n\n<!--section=installation-->\n<p>This plugin is not a simple Wordpress plugin. Beware.  You cannot just put the files in plugins and enable through the control panel.  This is because the database needs to be connected adn established BEFORE the plugins are loaded.<\/p>\n\n<p>So ... to install PDO For Wordpress please do the following:<\/p>\n\n<ol>\n<li><p>Step 1:\nunzip the files in your wp-content directory.  After unzipping the structure should look like this<\/p>\n\n<p>wp-content<br \/>\n-&gt;plugins<br \/>\n-&gt;themes<br \/>\n-&gt;pdo<br \/>\ndb.php<br \/>\nindex.php[maybe]<\/p>\n\n<p>The key thing is the presence of the pdo directory and the db.php file in the 'root' of the wp-content directory.<\/p><\/li>\n<li><p>Step 2:\nEdit your wp-config.php file so that:<\/p>\n\n<p>this line of code is placed directly after the define('COLLATE',''); line:<\/p>\n\n<pre><code>define('DB_TYPE', 'sqlite');    \/\/mysql or sqlite`\n<\/code><\/pre>\n\n<p>Note: currently only mysql and sqlite are supported. I hope that more flavours will appear soon.<\/p>\n\n<p>As part of the general wordpress installation you should define your secret keys too (in wp-config.php).<\/p><\/li>\n<\/ol>\n\n<p>and that's it.  two steps.<\/p>\n\n<p>The next time you load your wordpress installation it will automatically create the database and take you through the basic Wordpress installation routine.\nIf you have problems with the installation you should receive a meaningful error messsage.  If not, the most common error by far is permissions.  You MUST make sure that php can read\/write to wp-content\/database.<\/p>\n\n<!--section=faq-->\n<p>What databases are supported?<\/p>\n\n<p>Currently the basic layer supports any database that is supported by PDO.<\/p>\n\n<ul>\n<li>MS SQL Server (PDO) ?  Microsoft SQL Server and Sybase Functions (PDO_DBLIB)  <\/li>\n<li>Firebird\/Interbase (PDO) ?  Firebird\/Interbase Functions (PDO_FIREBIRD)  <\/li>\n<li>IBM (PDO) ?  IBM Functions (PDO_IBM)  <\/li>\n<li>Informix (PDO) ?  Informix Functions (PDO_INFORMIX)  <\/li>\n<li>MySQL (PDO) ?  MySQL Functions (PDO_MYSQL)  <\/li>\n<li>Oracle (PDO) ?  Oracle Functions (PDO_OCI)  <\/li>\n<li>ODBC and DB2 (PDO) ?  ODBC and DB2 Functions (PDO_ODBC)  <\/li>\n<li>PostgreSQL (PDO) ?  PostgreSQL Functions (PDO_PGSQL)  <\/li>\n<li>SQLite (PDO) ?  SQLite Functions (PDO_SQLITE)  <\/li>\n<\/ul>\n\n<p>Note that through the PDO_ODBC extension, all ODBC supported databases are also supported, subject to drivers being available<\/p>\n\n<p>HOWEVER each database needs its own driver and currently the only drivers written for this plugin are for<\/p>\n\n<ul>\n<li>sqlite and   <\/li>\n<li>mysql<\/li>\n<\/ul>\n\n<p>The database does not install.  Why?<\/p>\n\n<p>the main reason for this is permissions.  The php process on your server needs to have permissions to create files and directories. \nPlease contact me by leaving a comment at rathercurious.net if this is affecting you.<\/p>","raw_excerpt":"This &#039;plugin&#039; enables WP to use databases supported by PHP&#039;s PDO abstraction layer. Currently, mysql and sqlite drivers are provided.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/3304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=3304"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/jpadie"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=3304"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=3304"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=3304"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=3304"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=3304"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=3304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}