<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>evardsson.com: stuff that w0rks &#187; Projects</title>
	<atom:link href="http://www.evardsson.com/blog/category/projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.evardsson.com/blog</link>
	<description>tweaks and hacks, php, python, music, home and ???</description>
	<lastBuildDate>Thu, 29 Jul 2010 19:25:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>New Project: SPDO</title>
		<link>http://www.evardsson.com/blog/2009/01/28/new-project-spdo/</link>
		<comments>http://www.evardsson.com/blog/2009/01/28/new-project-spdo/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 02:00:40 +0000</pubDate>
		<dc:creator>Sjan Evardsson</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgresQL]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SPDO]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.evardsson.com/blog/?p=284</guid>
		<description><![CDATA[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 dozen or so of them are really functional and (in a few cases) very polished pieces of work. So why [...]]]></description>
			<content:encoded><![CDATA[<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>
<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>
<ol>
<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>
<li>I like to have coding signatures that are (reasonably) consistent across different languages &#8211; in this case Python and PHP.</li>
<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>
</ol>
<p>Currently implemented in</p>
<ul>
<li>Python:
<ul>
<li>PostgreSQL (with prepared statements)</li>
<li>SQLite (no prepared statements).</li>
</ul>
</li>
<li>PHP
<ul>
<li>PostgreSQL (with prepared statements)</li>
<li>MySQL (with prepared statements)</li>
<li>SQLite (no prepared statements)</li>
</ul>
</li>
</ul>
<p>Here&#8217;s an example of how they work (in most simplistic terms):</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8aece56694a">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8aece56694a').style.display='block';document.getElementById('plain_synthi_4c8aece56694a').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
#in Python
from pyDB import *
db = pyDB('mysite')
newid = db.insert('INSERT INTO test (name, value) VALUES (?,?)',['foo','bar'])
update_count = db.update('UPDATE test SET value=? WHERE id=?',['baz',newid])
results = db.select('SELECT * FROM test')
for row in results:
    for i in row:
        print &#034;\t&#034;, i,&#034;\t&#034;, row[i]
delete_count = db.delete('DELETE FROM test WHERE id=?',[newid])
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8aece56694a">
<div class="synthi_header" style="font-weight:bold;"> Python <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8aece56694a').style.display='block';document.getElementById('styled_synthi_4c8aece56694a').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="python" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #808080; font-style: italic;">#in Python</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #ff7700;font-weight:bold;">from</span> pyDB <span style="color: #ff7700;font-weight:bold;">import</span> *</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">db = pyDB<span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;mysite&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">newid = db.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;INSERT INTO test (name, value) VALUES (?,?)&#8217;</span>,<span style="color: black;">&#91;</span><span style="color: #483d8b;">&#8216;foo&#8217;</span>,<span style="color: #483d8b;">&#8216;bar&#8217;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">update_count = db.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;UPDATE test SET value=? WHERE id=?&#8217;</span>,<span style="color: black;">&#91;</span><span style="color: #483d8b;">&#8216;baz&#8217;</span>,newid<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">results = db.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;SELECT * FROM test&#8217;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> results:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> row:</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>, i,<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>, row<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">delete_count = db.<span style="color: black;">delete</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&#8216;DELETE FROM test WHERE id=?&#8217;</span>,<span style="color: black;">&#91;</span>newid<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c8aece56f765">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c8aece56f765').style.display='block';document.getElementById('plain_synthi_4c8aece56f765').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
//in PHP
require_once('phpdb.php');
$db = new phpDB('test');
$newid = $db->insert('INSERT INTO test (name, value) VALUES (?,?)',array('foo','bar'));
$update_count = $db->update('UPDATE test SET value=? WHERE id=?',array('baz',newid));
$results = db->select('SELECT * FROM test');
foreach($results as $row)
{
    foreach ($row as $key=>$val)
    {
        print &#034;\t$key\t$val&#034;;
    }
}
$delete_count = $db->delete('DELETE FROM test WHERE id=?',array($newid));
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c8aece56f765">
<div class="synthi_header" style="font-weight:bold;"> PHP <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c8aece56f765').style.display='block';document.getElementById('styled_synthi_4c8aece56f765').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="php" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #808080; font-style: italic;">//in PHP</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;phpdb.php&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #0000ff;">$db</span> = <span style="color: #000000; font-weight: bold;">new</span> phpDB<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;test&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #0000ff;">$newid</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">insert</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;INSERT INTO test (name, value) VALUES (?,?)&#8217;</span>,<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;foo&#8217;</span>,<span style="color: #ff0000;">&#8216;bar&#8217;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #0000ff;">$update_count</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;UPDATE test SET value=? WHERE id=?&#8217;</span>,<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;baz&#8217;</span>,newid<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #0000ff;">$results</span> = db-&gt;<span style="color: #006600;">select</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;SELECT * FROM test&#8217;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$key</span>=&gt;<span style="color: #0000ff;">$val</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>$key<span style="color: #000099; font-weight: bold;">\t</span>$val&quot;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal; font-size: 1.2em;"><span style="color: #0000ff;">$delete_count</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">delete</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;DELETE FROM test WHERE id=?&#8217;</span>,<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newid</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
<p>The page with links to the code is in the list up top, and everything is MIT license. Enjoy.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=New+Project%3A+SPDO+http://dg839.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;submitHeadline=New+Project%3A+SPDO" title="Post to Yahoo Buzz"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;submitHeadline=New+Project%3A+SPDO" title="Post to Yahoo Buzz">Buzz This Post</a> <a class="tt" href="http://delicious.com/post?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Delicious"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://delicious.com/post?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Delicious">Delicious</a> <a class="tt" href="http://digg.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Digg"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://ping.fm/ref/?method=microblog&amp;title=New+Project%3A+SPDO&amp;link=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/" title="Post to Ping.fm"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-ping.png" alt="Post to Ping.fm" /></a> <a class="tt" href="http://ping.fm/ref/?method=microblog&amp;title=New+Project%3A+SPDO&amp;link=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/" title="Post to Ping.fm">Ping This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Reddit"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to StumbleUpon"><img class="nothumb" src="http://www.evardsson.com/blog/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.evardsson.com/blog/2009/01/28/new-project-spdo/&amp;title=New+Project%3A+SPDO" title="Post to StumbleUpon">Stumble This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.evardsson.com/blog/2009/01/28/new-project-spdo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
