<?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>Brandon Checketts &#187; General</title> <atom:link href="http://www.brandonchecketts.com/archives/category/general/feed" rel="self" type="application/rss+xml" /><link>http://www.brandonchecketts.com</link> <description>Web Programming, Linux System Administation, and other geeky stuff</description> <lastBuildDate>Sun, 25 Jul 2010 00:50:58 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.1</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Southeast Linux Fest Presentation on MySQL Replication</title><link>http://www.brandonchecketts.com/archives/southeast-linux-fest-presentation-on-mysql-replication</link> <comments>http://www.brandonchecketts.com/archives/southeast-linux-fest-presentation-on-mysql-replication#comments</comments> <pubDate>Mon, 14 Jun 2010 02:01:51 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[LUG]]></category> <category><![CDATA[Linux System Administration]]></category> <category><![CDATA[MySQL]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=460</guid> <description><![CDATA[I was fortunate to be selected to give a presentation at the 2010 Southeast Linux Fest held this year in Greenville, SC. The topic was MySQL replication which I picked from a similar presentation I gave about about 1.5 years ago at my local LUG.   I&#8217;ve configured plenty of replicated servers and I [...]]]></description> <content:encoded><![CDATA[<p>I was fortunate to be selected to give a presentation at the 2010 <a
href="http://www.southeastlinuxfest.org/">Southeast Linux Fest</a> held this year in Greenville, SC. The topic was MySQL replication which I picked from a similar presentation I gave about about 1.5 years ago at my <a
href="http://www.uga.edu/chugalug/">local LUG</a>.   I&#8217;ve configured plenty of replicated servers and I think that I understand it well enough to explain it to others.</p><p>The 2-hour presentation is about half slides and half demo.  Throughout the course of the presentation I set up a simple master-slave.  Then I add a second slave.   Taking it a step farther I set up the three servers to replicate in a chain, and finally I configure them to replicate in a full circle so that changes made on one are propagated to all of the others.  I intentionally do things that break replication at certain points to show some of the limitations and configurable features that can help it to work.</p><p>Slides for the presentation are available <a
href="/downloads/self2010-mysql-replication.odp">OpenOffice format</a>.</p><p>The presentation was recorded, so hopefully the SELF team will have those videos available shortly.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/southeast-linux-fest-presentation-on-mysql-replication/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Script to Import Static Pages into GetSimple CMS</title><link>http://www.brandonchecketts.com/archives/script-to-import-static-pages-into-getsimple-cms</link> <comments>http://www.brandonchecketts.com/archives/script-to-import-static-pages-into-getsimple-cms#comments</comments> <pubDate>Thu, 13 May 2010 04:30:52 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Websites]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=457</guid> <description><![CDATA[I&#8217;ve recently been impressed with a very simple Content Management System called GetSimple.  It provides just the very basics that allows a user to edit their own website content.  For brochure sites with owners who don&#8217;t want the complexity of a larger CMS, I think it is pretty ideal.
When I develop a site [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve recently been impressed with a very simple Content Management System called <a
href="http://get-simple.info/">GetSimple</a>.  It provides just the very basics that allows a user to edit their own website content.  For brochure sites with owners who don&#8217;t want the complexity of a larger CMS, I think it is pretty ideal.</p><p>When I develop a site though, I typically have a header and footer, and then all of the content pages exist as PHP files that simply include that header and footer.  Converting a static site like that into the CMS takes a bunch of copy/pasting.  I always try to avoid such tedious jobs, and so developed a script  that will import those static pages into a GetSimple installation.</p><p>To run this script, I wanted to import a bunch of files in a &#8217;static&#8217; directory where I had moved all of the static files to.  I then ran this from the command line to import all of the content into GetSimple</p><pre>
# for file in `find static -type f`
> do
> ./getsimple_import_file.php $file
> done
</pre><p>The script is available as <a
href="http://www.brandonchecketts.com/downloads/getsimple_import_file.php">getsimple_import_file.php</a></p><p>It takes a little configuration before running it.   It works by simulating the data that you would submit when creating the page through the web interface, so we have to fake the necessary session cookie.  Uncomment the bit in the middle that will display your cookie and run the script once.  You&#8217;ll need to copy your cookie name and value into the script before doing any actual imports.</p><p>Once you&#8217;ve done that, you will probably want to change the regular expression that attempts to grab the page title from your file.  You may also want to manipulate how it figures the URL to use.</p><p>Feel free to post comments here if  you found this useful, or made any changes  you&#8217;d like to share with other users</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/script-to-import-static-pages-into-getsimple-cms/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Skipping the DROP TABLE, CREATE TABLE statements in a large mysqldump file.</title><link>http://www.brandonchecketts.com/archives/skipping-the-drop-table-create-table-statements</link> <comments>http://www.brandonchecketts.com/archives/skipping-the-drop-table-create-table-statements#comments</comments> <pubDate>Wed, 28 Apr 2010 14:03:52 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[Programming]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=451</guid> <description><![CDATA[I have a large table of test data that I&#8217;m copying into some development environments.  I exported the table with a mysqldump which has a DROP TABLE and CREATE TABLE statements at the topDROP TABLE IF EXISTS `mytable`;
CREATE TABLE `mytable` (
`somecol` varchar(10) NOT NULL default '',
... other columns ...
[...]]]></description> <content:encoded><![CDATA[<p>I have a large table of test data that I&#8217;m copying into some development environments.  I exported the table with a mysqldump which has a DROP TABLE and CREATE TABLE statements at the top</p><pre>
DROP TABLE IF EXISTS `mytable`;
CREATE TABLE `mytable` (
  `somecol` varchar(10) NOT NULL default '',
   ... other columns ...
  PRIMARY KEY  (`somecol`),
  KEY `isbn10` (`somecol`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
</pre><p>The problem is that the developer has altered the table and re-importing the test data would undo those changes.  Editing the text file is impractical because of its size (500 MB gzipped).  So I came up with this workaround which just slightly alters the SQL using sed so that it doesn&#8217;t try to drop or recreate the table.  It comments out the DROP TABLE line, and creates the new table in the test database instead of the real database.</p><pre>
zcat bigfile.sql.gz |sed "s/DROP/-- DROP/"|sed "s/CREATE TABLE /CREATE TABLE test./"|mysql databasename
</pre>]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/skipping-the-drop-table-create-table-statements/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Sleeping for a random amount of time in a shell script</title><link>http://www.brandonchecketts.com/archives/sleeping-for-a-random-amount-of-time-in-a-shell-script</link> <comments>http://www.brandonchecketts.com/archives/sleeping-for-a-random-amount-of-time-in-a-shell-script#comments</comments> <pubDate>Fri, 26 Mar 2010 21:17:05 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=444</guid> <description><![CDATA[You can use the special $RANDOM environment variable to get a random number and divide it by the maximum number of seconds that you want to wait.  Use the remainder as the number of seconds to sleep since it will always be between zero and the max you specified.  This example will sleep [...]]]></description> <content:encoded><![CDATA[<p>You can use the special $RANDOM environment variable to get a random number and divide it by the maximum number of seconds that you want to wait.  Use the remainder as the number of seconds to sleep since it will always be between zero and the max you specified.  This example will sleep anywhere between zero and 10 minutes (600 seconds)</p><pre>
 /bin/sleep/sleep   `/usr/bin/expr $RANDOM % 600`
</pre><p>Purists will note that it isn&#8217;t truly random.  The maximum value for $RANDOM is 32767 which is not evenly divisible by most likely values, but it is close enough.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/sleeping-for-a-random-amount-of-time-in-a-shell-script/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Installing SVN and Trac on a CentOS 5 server</title><link>http://www.brandonchecketts.com/archives/installing-svn-and-trac-on-a-centos-5-server</link> <comments>http://www.brandonchecketts.com/archives/installing-svn-and-trac-on-a-centos-5-server#comments</comments> <pubDate>Fri, 19 Mar 2010 20:13:35 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category> <category><![CDATA[Programming]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=442</guid> <description><![CDATA[Make sure that you have the RPMForge repository enabled.  Install Subversion, mod_dav_svn, and trac.  This will install a few required dependencies (ie: neon and some python utils)# yum install subversion mod_dav_svn mod_python tracCreate a directory for your repositories, and an initial repository for testing, and create your htpasswd file.  Then create a [...]]]></description> <content:encoded><![CDATA[<p>Make sure that you have the <a
href="https://rpmrepo.org/RPMforge/Using">RPMForge repository enabled</a>.  Install Subversion, mod_dav_svn, and trac.  This will install a few required dependencies (ie: neon and some python utils)</p><pre>
# yum install subversion mod_dav_svn mod_python trac
</pre><p>Create a directory for your repositories, and an initial repository for testing, and create your htpasswd file.  Then create a trac environment and set it up.</p><pre>
# mkdir /home/svn/
# svnadmin create testrepo
# chown -R apache:apache /home/svn/*
# htpasswd -c  /home/svn/.htpasswd brandon

#mkdir /home/trac/
# trac-admin /home/trac/ initenv
    ... answer questions as appropriate ...
# chown apache:apache /home/trac/*
# htpasswd -c  /home/svn/.htpasswd brandon
</pre><p>Add this to your Apache configuration in the relevant place (I like to put it under an SSL VirtualHost)</p><pre>
    &lt;Location /svn&gt;
        DAV svn
        SVNParentPath /home/svn/
        #SVNListParentPath on
        # Authentication
        AuthType Basic
        AuthName "RoundSphere SVN Repository"
        AuthUserFile /home/svn/.htpasswd
        Order deny,allow
        Require valid-user
    &lt;/Location&gt;
    &lt;Location /trac&gt;
        SetHandler mod_python
        PythonHandler trac.web.modpython_frontend
        PythonOption TracEnv /home/trac
        PythonOption TracUriRoot /trac
        # Authentication
        AuthType Basic
        AuthName “MyCompany Trac Environment"
        AuthUserFile /home/svn/.htpasswd
        Require valid-user
    &lt;/Location&gt;
</pre><p>Now test to make sure that you can view your test repository in a browser and that it prompts for a username and password as desired:</p><p>https://your-hostname/svn/testrepo/</p><p>You should retrieve a plain looking page that mentions the name of your repository and that it is at Revision 0</p><p>You should also be able to access your trac installation at</p><p>https://your-hostname/trac/</p><p>Customize your logo, change the home page, start making some tickets, using the wiki and get to work.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/installing-svn-and-trac-on-a-centos-5-server/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Pear Upgrade Installer</title><link>http://www.brandonchecketts.com/archives/pear-upgrade-installer</link> <comments>http://www.brandonchecketts.com/archives/pear-upgrade-installer#comments</comments> <pubDate>Thu, 18 Mar 2010 21:19:56 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=440</guid> <description><![CDATA[I was trying to install PHPUnit today, but the box wouldn&#8217;t allow me because the Pear Installer version wasn&#8217;t current.  But there was no obvious way to upgrade the pear installer.[root@ci /]# pear install phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, channel://pear.symfony-project.com/YAML, use --alldeps to download automatically
phpunit/PHPUnit requires PEAR Installer (version >= 1.8.1), installed [...]]]></description> <content:encoded><![CDATA[<p>I was trying to install PHPUnit today, but the box wouldn&#8217;t allow me because the Pear Installer version wasn&#8217;t current.  But there was no obvious way to upgrade the pear installer.</p><pre>
[root@ci /]# pear install phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, channel://pear.symfony-project.com/YAML, use --alldeps to download automatically
phpunit/PHPUnit requires PEAR Installer (version >= 1.8.1), installed version is 1.4.9
phpunit/PHPUnit can optionally use package "pear/Image_GraphViz" (version >= 1.2.1)
phpunit/PHPUnit can optionally use package "pear/Log"
phpunit/PHPUnit can optionally use package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "json"
phpunit/PHPUnit can optionally use PHP extension "xdebug" (version >= 2.0.5)
No valid packages found
install failed
</pre><p>The trick is to install the PEAR package with &#8211;force to make it go through</p><pre>
[root@ci /]# pear upgrade --force PEAR
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.3.6 is not the recommended version 1.3.3
warning: pear/Archive_Tar requires PEAR Installer (version >= 1.5.4), installed version is 1.4.9
downloading PEAR-1.9.0.tgz ...
Starting to download PEAR-1.9.0.tgz (291,634 bytes)
.............................................................done: 291,634 bytes
downloading Archive_Tar-1.3.6.tgz ...
Starting to download Archive_Tar-1.3.6.tgz (17,600 bytes)
...done: 17,600 bytes
upgrade ok: channel://pear.php.net/Archive_Tar-1.3.6
upgrade ok: channel://pear.php.net/PEAR-1.9.0
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
To install use "pear install pear/PEAR#featurename"
</pre><p>From there, you can continue on the the PHPUnit Install</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/pear-upgrade-installer/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Installing the Pandora One client on 64-bit Ubuntu 9.10</title><link>http://www.brandonchecketts.com/archives/installing-the-pandora-one-client-on-64-bit-ubuntu-910</link> <comments>http://www.brandonchecketts.com/archives/installing-the-pandora-one-client-on-64-bit-ubuntu-910#comments</comments> <pubDate>Tue, 26 Jan 2010 16:51:41 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category> <category><![CDATA[Linux Desktop]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=436</guid> <description><![CDATA[I was surprised and happy to see that the Pandora One client should work on Linux.  It uses the Adobe Air framework which means that Pandora doesn&#8217;t have to write a specific Linux variant.
However, installing it on a modern 64-Bit Ubuntu 9.10 install took just a bit of manipulation to get it [...]]]></description> <content:encoded><![CDATA[<p>I was surprised and happy to see that the <a
href="http://www.pandora.com/desktop_app">Pandora One client</a> <strong>should</strong> work on Linux.  It uses the Adobe Air framework which means that Pandora doesn&#8217;t have to write a specific Linux variant.</p><p>However, installing it on a modern 64-Bit Ubuntu 9.10 install took just a bit of manipulation to get it to work.  Pandora provides some basic instructions for Linux users <a
href="http://blog.pandora.com/faq/#1662">here</a>, even though Linux is officially unsupported.  Those instructions, along with the Adobe AIR notes <a
href="http://kb2.adobe.com/cps/408/kb408084.html">here</a> provided enough information for me to get it installed and working.</p><p>Here&#8217;s what I did:</p><ul><li>Start out <a
href="http://www.pandora.com/desktop_app">at the Pandora One site</a></li><li>Click on the &quot;Download Pandora Desktop&quot; link and save that file to /tmp</li><li>Follow the link to Install Adobe Air and save that file to /tmp also</li><li>Open a shell, and chmod the Adobe Air installer to 755 and then run it.</li><li>Go through the Adobe AIR install until it completes</li><li>Once Adobe AIR is installed, you will need to put some 32-bit libraries in place to make it run correctly. Some of the steps on <a
href="http://kb2.adobe.com/cps/408/kb408084.html">Adobe&#8217;s site</a> work, and some don&#8217;t, so this is what I did</li><li>Download the two .deb files for <a
href="http://mirrors.kernel.org/ubuntu/pool/main/n/nss/libnss3-1d_3.12.0%7Ebeta3-0ubuntu1_i386.deb">libnss3</a> and <a
href="http://mirrors.kernel.org/ubuntu/pool/main/n/nspr/libnspr4-0d_4.7.1%7Ebeta2-0ubuntu1_i386.deb">Libnspr4</a> to /tmp</li><li>From your shell, run:<pre>
 sudo file-roller ./libnss3-1d_3.12.0~beta3-0ubuntu1_i386.deb
</pre></li><li>Navigate to data.tar.gz =&gt; /usr =&gt; lib.  Click on all of the files in that directory and click Extract.  Type in /usr/lib32/ so that they extract there, then close all of the file-roller windows.</li><li>Do the same thing with the libnspr4 .deb file that you downloaded</li><li>Copy the adobe cert store into place with this command:<pre>
 sudo cp /usr/lib/libadobecertstore.so /usr/lib32
</pre></li><li>Now you can finally install the Pandora application by running:<pre>
sudo Adobe\ AIR\ Application\ Installer /tmp/pandora_2_0_2.air
</pre><p> That should install the application correctly.  It will add an icon to Applications / Accessories.</li><li>Upon starting up the Pandora One client, it currently complains about connecting to an untrusted server for me.  I have to click to accept for this session each time</li></ul><p>Now you should be able to play your Pandora music from your 64-bit Ubuntu 9.10 box.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/installing-the-pandora-one-client-on-64-bit-ubuntu-910/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Speed up a Linux Software Raid Rebuild</title><link>http://www.brandonchecketts.com/archives/speed-up-a-linux-software-raid-rebuild</link> <comments>http://www.brandonchecketts.com/archives/speed-up-a-linux-software-raid-rebuild#comments</comments> <pubDate>Mon, 25 Jan 2010 21:08:16 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[Data Recovery]]></category> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=432</guid> <description><![CDATA[I&#8217;m setting up software raid on a running server and it is taking forever for the initial sync of the raid drives on the 1TB hard disks.  It has been running for about 6 hours and says that it will take about 5 days (7400 minutes) as this pace:[root@host ~]# cat /proc/mdstat
md1 : active [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;m <a
href="http://www.brandonchecketts.com/archives/setting-up-software-raid-on-a-running-centos-5-server">setting up software raid on a running server</a> and it is taking forever for the initial sync of the raid drives on the 1TB hard disks.  It has been running for about 6 hours and says that it will take about 5 days (7400 minutes) as this pace:</p><pre>
[root@host ~]# cat /proc/mdstat
md1 : active raid1 sdb3[1] sda3[2]
      974559040 blocks [2/1] [_U]
      [>....................]  recovery =  3.9% (38109184/974559040) finish=7399.1min speed=2108K/sec
</pre><p>I did some read and write tests directly to the drives using dd to make sure that they were working okay, and they can operate at about 100 MB/s</p><pre>
[root@host ~]# dd if=/dev/zero of=/dev/sda2 bs=1024 count=1024000
    1048576000 bytes (1.0 GB) copied, 10.8882 seconds, 96.3 MB/s
[root@host ~]# dd if=/dev/zero of=/dev/sdb2 bs=1024 count=1024000
    1048576000 bytes (1.0 GB) copied, 11.1162 seconds, 94.3 MB/s
[root@host ~]# dd if=/dev/sda2 of=/dev/null bs=1024 count=1024000
    1048576000 bytes (1.0 GB) copied, 10.2829 seconds, 102 MB/s
[root@host ~]# dd if=/dev/sdb2 of=/dev/null bs=1024 count=1024000
    1048576000 bytes (1.0 GB) copied, 10.5109 seconds, 99.8 MB/s
</pre><p>What I failed to realize is that there is a configurable limit for the min and max speed of the rebuild.  Those parameters are configured in /proc/sys/dev/raid/speed_limit_min and /proc/sys/dev/raid/speed_limit_max.   They default to a pretty slow 1MB/s minimum which was causing it to take forever.</p><p>Increasing the maximum limit didn&#8217;t automatically make it faster either.  I had to increase the minimum limit to get it to jump up to a respectable speed.</p><p>[root@host ~]# echo 100000 > /proc/sys/dev/raid/speed_limit_min</p><pre>
[root@host ~]# watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat
md1 : active raid1 sdb3[1] sda3[2]
      974559040 blocks [2/1] [_U]
      [=>...................]  recovery =  7.7% (75695808/974559040) finish=170.5min speed=87854K/sec
</pre><p>Now it is up around 87 MB/s and will take just a few hours to complete the rest of the drive.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/speed-up-a-linux-software-raid-rebuild/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>PHP Wrapper Class for a Read-only database</title><link>http://www.brandonchecketts.com/archives/php-wrapper-class-for-a-read-only-database</link> <comments>http://www.brandonchecketts.com/archives/php-wrapper-class-for-a-read-only-database#comments</comments> <pubDate>Tue, 05 Jan 2010 04:11:58 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Linux System Administration]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=421</guid> <description><![CDATA[This is a pretty special case of a database wrapper class where I wanted to discard any updates to the database, but want SELECT queries to run against an alternative read-only database.  In this instance, I have a planned outage of a primary database server, but would like the public-facing websites and web services [...]]]></description> <content:encoded><![CDATA[<p>This is a pretty special case of a database wrapper class where I wanted to discard any updates to the database, but want SELECT queries to run against an alternative read-only database.  In this instance, I have a planned outage of a primary database server, but would like the public-facing websites and web services to remain as accessible as possible.</p><p>I wrote this quick database wrapper class that will pass all SELECT queries on to a local replica of the database, and silently discard any updates.   On this site almost all of the functionality still works, but it obviously isn&#8217;t saving and new information while the primary database is unavailable.</p><p>Here is my class.  This is intended as a wrapper to an ADOdb class, but it is generic enough that I think it would work for many other database abstraction functions as well.</p><pre>
class db_unavailable {
    var $readonly_db;

    function __construct($readonly_db)
    {
        $this->query_db = $readonly_db;
    }

    function query($sql)
    {
        $args = func_get_args();
        if (preg_match("#(INSERT INTO|REPLACE INTO|UPDATE|DELETE)#i", $args[0])) {
            // echo "Unable to do insert/replace/update/delete query: $sql\n";
            return true;
        } else {
            return call_user_func_array(array($this->readonly_db, 'query'), $args);
        }
    }

    function __call($function, $args)
    {
        return call_user_func_array(array($this->readonly_db, $function), $args);
    }
}
</pre><p>I simply create my $query_db object that points to the read-only database.  Then create my main $db object as a new db_unavailable() object.  Any select queries against $db will behave as they normally do, and data-modifying queries will be silently discarded.</p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/php-wrapper-class-for-a-read-only-database/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>LUG Presentation on SQL Basics</title><link>http://www.brandonchecketts.com/archives/lug-presentation-on-sql-basics</link> <comments>http://www.brandonchecketts.com/archives/lug-presentation-on-sql-basics#comments</comments> <pubDate>Fri, 18 Dec 2009 03:52:59 +0000</pubDate> <dc:creator>Brandon</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[LUG]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category><guid
isPermaLink="false">http://www.brandonchecketts.com/?p=416</guid> <description><![CDATA[I gave a presentation tonight at my local Linux Users Group meeting on SQL Basics.   I had a fun time preparing the presentation and made up a bunch of examples having to do with Santa&#8217;s database.
It started out with a simple table for kids who were either naughty or nice.  [...]]]></description> <content:encoded><![CDATA[<p>I gave a presentation tonight at my local <a
href="http://www.uga.edu/chugalug/">Linux Users Group</a> meeting on SQL Basics.   I had a fun time preparing the presentation and made up a bunch of examples having to do with Santa&#8217;s database.</p><p>It started out with a simple table for kids who were either naughty or nice.  We then added some reports to that.   Then imported kids&#8217; wish lists from CSV files.  From there we were able to generate some manufacturing reports for the workshop.</p><p>When we joined the wish list table with the kids table, we were then able to generate a sleigh-loading report which included only gifts for kids who had been good.   Then we got even more complicated and introduced several joins with some complicated mathematics to select gifts for kids within a certain radius from a given zip code.</p><p>The presentation is <a
href="/downloads/CHUGALUG Chrsitmas SQL.ppt">available for download here</a>.  And Brian recorded part of the presentation which is available to view <a
href="http://www.ustream.tv/recorded/3205751">on uStream.tv</a> or here. (We&#8217;re still experimenting with getting the video recording set up correctly)</p><p><object
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="386" id="utv528934" name="utv_n_851113"><param
name="flashvars" value="loc=%2F&amp;autoplay=false&amp;vid=3205751" /><param
name="allowfullscreen" value="true" /><param
name="allowscriptaccess" value="always" /><param
name="src" value="http://www.ustream.tv/flash/video/3205751" /><embed
flashvars="loc=%2F&amp;autoplay=false&amp;vid=3205751" width="480" height="386" allowfullscreen="true" allowscriptaccess="always" id="utv528934" name="utv_n_851113" src="http://www.ustream.tv/flash/video/3205751" type="application/x-shockwave-flash" /></object></p> ]]></content:encoded> <wfw:commentRss>http://www.brandonchecketts.com/archives/lug-presentation-on-sql-basics/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 3/12 queries in 0.127 seconds using disk

Served from: www.brandonchecketts.com @ 2010-09-08 08:02:08 -->