{"id":284,"date":"2009-01-28T19:00:40","date_gmt":"2009-01-29T02:00:40","guid":{"rendered":"http:\/\/www.evardsson.com\/blog\/?p=284"},"modified":"2009-01-28T19:02:45","modified_gmt":"2009-01-29T02:02:45","slug":"new-project-spdo","status":"publish","type":"post","link":"https:\/\/www.evardsson.com\/blog\/2009\/01\/28\/new-project-spdo\/","title":{"rendered":"New Project: SPDO"},"content":{"rendered":"<p>I have just posted the (embarrassingly empty) page for my new pet project: SPDO (Sjan&#8217;s PDO) &#8211; in two flavors: <a href=\"http:\/\/www.php.net\">PHP<\/a> and <a href=\"http:\/\/python.org\/\">Python<\/a>.<\/p>\n<p>There are only about a thousand PDOs out there, and perhaps a dozen or so of them are really functional and (in a few cases) very polished pieces of work. So why am I messing with writing my own? A couple of reasons:<\/p>\n<ol>\n<li>I like to have coding signatures that are consistent, whether I am working with <a href=\"http:\/\/www.postgresql.org\/\">PostgreSQL<\/a>, <a href=\"http:\/\/www.mysql.com\/\">MySQL<\/a> or (heaven help us all) <a href=\"http:\/\/www.sqlite.org\/\">SQLite<\/a>.<\/li>\n<li>I like to have coding signatures that are (reasonably) consistent across different languages &#8211; in this case Python and PHP.<\/li>\n<li>I wanted to take advantage of Prepared Statements where I could, even though the PHP implementations of those are pretty weak (especially in the case of MySQL).<\/li>\n<\/ol>\n<p>Currently implemented in<\/p>\n<ul>\n<li>Python:\n<ul>\n<li>PostgreSQL (with prepared statements)<\/li>\n<li>SQLite (no prepared statements).<\/li>\n<\/ul>\n<\/li>\n<li>PHP\n<ul>\n<li>PostgreSQL (with prepared statements)<\/li>\n<li>MySQL (with prepared statements)<\/li>\n<li>SQLite (no prepared statements)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Here&#8217;s an example of how they work (in most simplistic terms):<\/p>\n<pre class=\"brush: python\">\r\n#in Python\r\nfrom pyDB import *\r\ndb = pyDB('mysite')\r\nnewid = db.insert('INSERT INTO test (name, value) VALUES (?,?)',['foo','bar'])\r\nupdate_count = db.update('UPDATE test SET value=? WHERE id=?',['baz',newid])\r\nresults = db.select('SELECT * FROM test')\r\nfor row in results:\r\n    for i in row:\r\n        print \"\\t\", i,\"\\t\", row[i]\r\ndelete_count = db.delete('DELETE FROM test WHERE id=?',[newid])\r\n<\/pre>\n<pre class=\"brush: php\">\r\n\/\/in PHP\r\nrequire_once('phpdb.php');\r\n$db = new phpDB('test');\r\n$newid = $db->insert('INSERT INTO test (name, value) VALUES (?,?)',array('foo','bar'));\r\n$update_count = $db->update('UPDATE test SET value=? WHERE id=?',array('baz',newid));\r\n$results = db->select('SELECT * FROM test');\r\nforeach($results as $row)\r\n{\r\n    foreach ($row as $key=>$val)\r\n    {\r\n        print \"\\t$key\\t$val\";\r\n    }\r\n}\r\n$delete_count = $db->delete('DELETE FROM test WHERE id=?',array($newid));\r\n<\/pre>\n<p>The page with links to the code is in the list up top, and everything is MIT license. Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have just posted the (embarrassingly empty) page for my new pet project: SPDO (Sjan&#8217;s PDO) &#8211; in two flavors: PHP and Python. There are only about a thousand PDOs out there, and perhaps a &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"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","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,13,43,33,14,37,34,88],"tags":[150,170,151,171,202,89],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-development","category-mysql","category-open-source","category-php","category-postgresql","category-projects","category-python","category-spdo","tag-mysql","tag-php","tag-postgresql","tag-python","tag-spdo","tag-sqlite"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pxT7i-4A","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":2,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":286,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions\/286"}],"wp:attachment":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}