{"id":17,"date":"2008-10-13T16:00:33","date_gmt":"2008-10-13T23:00:33","guid":{"rendered":"http:\/\/kellytehuna.com\/blog\/?p=17"},"modified":"2008-10-13T16:03:16","modified_gmt":"2008-10-13T23:03:16","slug":"php-data-access-layer","status":"publish","type":"post","link":"http:\/\/kellytehuna.com\/blog\/2008\/10\/13\/php-data-access-layer\/","title":{"rendered":"PHP Data Access Layer"},"content":{"rendered":"<p>For some time I&#8217;ve been toying with the idea of building my own, custom data access layer.\u00a0 Sure there are plenty out there.\u00a0 Some of them are HUGE (just think PEAR::DB, or <a title=\"ADOdb Library for PHP\" href=\"http:\/\/phplens.com\/adodb\/\" target=\"_blank\">ADOdb<\/a>), which isn&#8217;t a bad thing in and of itself if, and only if, they still perform well.\u00a0 I believe ADOdb performs pretty well, but I&#8217;ve not actually run the benchmarks to confirm this, so I won&#8217;t enter in to that argument.\u00a0 A quick Google search will bring up plenty of articles discussing the pros and cons of Database Abstraction Layers.<!--more--><\/p>\n<p>The reason I decided to create my own is simple: it will function the way I want it to and it will read the way I want it to.\u00a0 Isn&#8217;t that really what matters most?\u00a0 Other than performance, which can be improved over time by minor tweaks and factorizations of the codebase.<\/p>\n<p>The main motivation for my API is in fact inspired by the <a title=\"CodeIgniter - Open source PHP web application framework\" href=\"http:\/\/codeigniter.com\/\" target=\"_blank\">CodeIgnite Framework<\/a>, by <a title=\"EllisLab - Where Ideas Hatch!\" href=\"http:\/\/ellislab.com\">EllisLab, Inc<\/a>.\u00a0 What EllisLab has done, is created a <a title=\"Wikipedia - Fluent Interfaces\" href=\"http:\/\/en.wikipedia.org\/wiki\/Fluent_interface\" target=\"_blank\">fluent interface<\/a> for their database access layer, which is a fancy way of saying, they let piece your queries together by chaining the various methods of that data access object, one after the other so the entire things reads more fluently.<\/p>\n<p>For example, rather than typing the following:<\/p>\n<p><code class=\"php\">$dao-&gt;select(array('column','column2'));<br \/>\n$dao-&gt;from('table','t');<br \/>\n$dao-&gt;where('t.column=1 AND t.collumn!=4');<br \/>\n$dao-&gt;order_by('t.column','ASC');<br \/>\n$dao-&gt;execute();<\/code><\/p>\n<p>You could write that as:<\/p>\n<p><code class=\"php\">$dao-&gt;select(array('column','column2'))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;-&gt;from('table','t')<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;-&gt;where('t.column=1 AND t.collumn!=4')<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;-&gt;order_by('t.column','ASC')<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;-&gt;execute();<\/code><\/p>\n<p>I know there isn&#8217;t much difference between the two sets of method calls, but I like the latter much better.\u00a0 It reads nicer and you can kinda make out what the query will actually look like, without having to worry to much about syntax and what not.<\/p>\n<p>I&#8217;m hoping to be done with the initial API any day now and will likely be putting it to good use in Timeline, so I&#8217;ll see how well it performs soon enough.\u00a0 I&#8217;m looking forward to seeing whether I can meet all the goals I have set for myself over the next little while.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For some time I&#8217;ve been toying with the idea of building my own, custom data access layer.\u00a0 Sure there are plenty out there.\u00a0 Some of them are HUGE (just think PEAR::DB, or ADOdb), which isn&#8217;t a bad thing in and of itself if, and only if, they still perform well.\u00a0 I believe ADOdb performs pretty [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[17,11,12],"tags":[132,18,14],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-database-abstraction","category-software","category-timeline","tag-database-abstraction","tag-fluent-interface","tag-mysql"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2FJaA-h","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/posts\/17"}],"collection":[{"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":2,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":19,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions\/19"}],"wp:attachment":[{"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kellytehuna.com\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}