Using CouchDB With PHP

One of the things that is being done with our project, Scrib, is building it to use CouchDB as the back-end database. The data we’ll be storing is more suited to a ‘document-style’ database rather than relational, like MySQL (here’s some pros and cons of CouchDB vs. MySQL). One of the great bonuses is that it uses a RESTful HTTP-API, which means that all of the data is accessible via HTTP requests. It also uses JSON for data transfer and storage. This makes it relatively easy to create a web-interface as the data is in a format that is not defined (like XML) and can easily be parsed.

While Scrib is utilizing it through Python, the web interface is going to be built using a mixture of HTML, JavaScript, CSS and PHP.

Utilizing PHP on Couch

For this part of the project we are going to use PHP on Couch, a PHP wrapper class to make things easy.

Most of the time CouchDB is already installed inside Linux (Debian-based distros, at least). In Ubuntu you can install it via “sudo apt-get install couchdb” (those of you who are using MacOSX or Windows, you can find respective packages here and here.)

Here’s an example of how easy it is to use CouchDB inside PHP:

<?php
require_once 'couch.php';
require_once 'couchClient.php';
require_once 'couchDocument.php';

// The default port for CouchDB is 5984. Let's connect to it!
$client = new couchClient('http://path.to.server:5984','db_name');

// A quick test to see if our connection works:
// Connect to our database:
$doc = new couchDocument($client);

// Creating a document and adding in the first entry
$doc->set(array('_id'=>'UristMcMiner','name'=>'McMiner','firstname'=>'Urist'));

// Some quick tests
echo $doc->firstname . " " . $doc->name ; // should echo "Urist McMiner"
echo "<br/>"; // This will make a new line.
echo $doc->_id; // This would echo "UristMcMiner"

// This would change the document property of "name" to "McFarmer"
// and store the updated document in the database.
$doc->name = "McFarmer";

echo $doc->firstname . " " . $doc->name ; // should echo "Urist McFarmer"
?>

Posted in The Plank | Tagged , , , , | Leave a comment

Install ScummVM From Daily Build in Ubuntu

A friend of mine asked me how to install ScummVM from a daily build. Since I myself had not done this before, I thought I would write a little tutorial. For those who do not know (and who do not necessarily want to click the link above), ScummVM is “an implementation of LucasArts SCUMM interpreter”.

Requirements

First, we must clear any requirements that ScummVM needs in order to build. Luckily, there are only a few required dependencies: SDL 1.2.x and build-essential which are both in the Ubuntu repositories. The rest of the optional requirements are (as of Ubuntu 10.04) already installed. These are:

  • flac: required to play compressed games without quality loss
  • libmad: libmad is for playing mp3-compressed games
  • libogg and libvorbis: to play OGG-Vorbis-compressed games
  • libmpeg2: some games use re-recoded cutscenes

One thing I always do when setting up my environment to build an application is make sure that the dependencies are installed, whether or not I think they are:

$ sudo apt-get install build-essential libsdl1.2-dev libsdl1.2debian flac libmad0 libogg0 libvorbis0a libmpeg2-4

The line above will install the required dependency as well as the optional dependencies if they are not available. If you do not want to install one of the optional dependencies, do not add its name into the list.

Source Files

We are now ready to grab the latest sources for ScummVM. They are available from this website. Download the newest source, which generally shows up first on the list. Make sure you download from the “Source” column. For this tutorial, I decided to move the downloaded file from my Downloads to ~/Desktop/tmp/

After this is downloaded, extract it to an empty folder. When the extraction is complete, you should have a scummvm folder with its contents. To extract via the Terminal (file name will be different for you):

$ bunzip2 scummvm-20100727.bz2
$ tar -xvf scummvm-20100727.tar
$ cd scummvm

You will notice that the above shows us changing the directory (cd) to the newly unarchived folder. From here we will want to make sure that our machine has everything needed for building. We do this by running the configure file. If this completes successfully, we will then run make to compile, and make install to install the application on our system.

(If you do not want to install this, you can still run it from this folder with ./scummvm. You won’t need to do the “&& make install”)

$ ./configure
$ sudo make && make install

After this is complete, you should be able to now run scummvm. If you run into any problems, please let me know and I will do what I can to help you.

Posted in The Plank | Tagged , , , | 3 Comments

Installing 32-bit Arch Linux Inside 64-bit

Arch Linux is a great Linux distribution for those who wish to install a minimal setup and configure their system just the way they want. Coming from a Debian-based distribution (Ubuntu), I have learned that installing 32-bit applications is not as easy as downloading the ia32-lib package.

The first time I downloaded 32-bit libraries inside Arch Linux, I figured out that they can overwrite or modify existing files. After refreshing my install, I set about for a better way to run 32-bit programs. What I found was a wiki entry inside the ArchWiki. After going through the steps a few times, I decided to create a script that would automate the steps to make installing it again less cumbersome.

Since the process can be a bit intimidating for people less acquainted with Linux and the use of the terminal, I have made my script available for download. Let me know how it works for you!

Posted in The Plank | Tagged , | 3 Comments