document.write('<div class="php" style="font-family: monospace;"><br />');
document.write('<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">class</span> SimpleDB_Connection<br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$conn</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$error</span> = <span style="color: #ff0000;">\'No Error\'</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> SimpleDB_Connection<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$hostname</span> = <span style="color: #ff0000;">\'localhost\'</span>, <span style="color: #0000ff;">$username</span> = <span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #0000ff;">$password</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span> = @<a target="_blank"&nbsp; href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$hostname</span>, <span style="color: #0000ff;">$username</span>, <span style="color: #0000ff;">$password</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">error</span> = <span style="color: #ff0000;">\'Could not connect to database.\'</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> query<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">error</span> = <span style="color: #ff0000;">\'Not connected to database.\'</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$res</span> = @<a target="_blank"&nbsp; href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$res</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">error</span> = <a target="_blank"&nbsp; href="http://www.php.net/mysql_error"><span style="color: #000066;">mysql_error</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleDB_Result<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$res</span>, <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> getError<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">error</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #000000; font-weight: bold;">class</span> SimpleDB_Result<br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$conn</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$res</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$numRows</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000ff;">$numAffected</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> SimpleDB_Result<span style="color: #66cc66;">&#40;</span>&amp;<span style="color: #0000ff;">$res</span>, &amp;<span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">res</span> = <span style="color: #0000ff;">$res</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span> = <span style="color: #0000ff;">$conn</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> getNext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$res</span> = @<a target="_blank"&nbsp; href="http://www.php.net/mysql_fetch_assoc"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">res</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> getNumRows<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$res</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">numRows</span> ? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">numRows</span> : @<a target="_blank"&nbsp; href="http://www.php.net/mysql_num_rows"><span style="color: #000066;">mysql_num_rows</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">res</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> getNumAffected<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$res</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">numAffected</span> ? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">numAffected</span> : @<a target="_blank"&nbsp; href="http://www.php.net/mysql_affected_rows"><span style="color: #000066;">mysql_affected_rows</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">conn</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$res</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/**<br />');
document.write('&nbsp;* EXAMPLES:<br />');
document.write('&nbsp;*/</span><br />');
document.write('<br />');
document.write('<span style="color: #0000ff;">$db</span> = <span style="color: #000000; font-weight: bold;">new</span> SimpleDB_Connection<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'localhost\'</span>, <span style="color: #ff0000;">\'username\'</span>, <span style="color: #ff0000;">\'password\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">\'SELECT *<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM `users`<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE `userid` &lt; 99\'</span>;<br />');
document.write('<span style="color: #0000ff;">$result</span> = <span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$result</span><span style="color: #66cc66;">&#41;</span> <a target="_blank"&nbsp; href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">getError</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$result</span>-&gt;<span style="color: #006600;">getNumRows</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <a target="_blank"&nbsp; href="http://www.php.net/die"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">\'No Results\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span> = <span style="color: #0000ff;">$result</span>-&gt;<span style="color: #006600;">getNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <a target="_blank"&nbsp; href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;{$row[\'username\']}&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;<br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">?&gt;</span><br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/446/1/" target="_blank">byteMyCode</a>.</div>');
