Posts tagged: sqlite

SQLite and Perl

SQLite is a really cool utility. I just started using it with the Perl scripts that make up my NintendoDS WarDriving project. If you’re reading this, you probably want to know how to install the modules to get SQLite working with Perl (in a linux environment).

You’ll need two files for this. The first is the perl DBI (Database Interface) module. The current version, as of this writing, is DBI-1.607 (download).

The second file is the perl DBD-SQLite module. The current version is DBD-SQLite-1.14 (download).

Also, make sure you have build-essential installed! It is required for “make” and “make install”.

Before we start, it’s worth noting that SQLite is so small (around the 200KB range) that it is actually provided in the DBD-SQLite module. So you don’t need the “official” SQLite package installed on your system. The module is the only requirement to work with Perl.

Installation

DBI needs to be installed first. Unpack DBI-1.607

tar xzf DBI-1.607.tar.gz
cd DBI-1.607/

and then create the Makefile, run the make file, install and clean

perl Makefile.PL
make
sudo make install
make clean

And that is it for DBI. You can delete the DBI-1.607/ directory now, if you like.

cd ..
rm -rf DBI-1.607/

Next, do the same procedure for DBD-SQLite-1.14

tar xzf DBD-SQLite-1.14.tar.gz
cd DBD-SQLite-1.14/
perl Makefile.PL
make
sudo make install
make clean
cd ..
rm -rf DBD-SQLite-1.14/

And you are ready to rock and roll with SQLite and Perl.

SQLite and PHP5 in LAMP

It seems that most articles written about SQLite and PHP are at least two years old and might leave some feeling like they are outdated and do not work. Here’s something recently dated (relatively speaking, assuming you’re reading this in 2008).

This article will help you get sqlite working with a directory hosted in your /home that is symlinked to /var/www

Using your favorite package manager, install a LAMP (Linux, Apache, MySQL, Perl) server. Ignore the fact that you are installing M (for MySQL).

Next, use the package manager to install php5-sqlite (NOTE: this is assuming that your package manager installs PHP5 by default)

Restart the apache webserver

sudo /etc/init.d/apache2 restart

And now php5-sqlite should be playing nice with apache.

At this point, I ran into trouble. I couldn’t get any examples of sqlite within PHP to work properly. The problem: permissions.

Create the directory that will host the files.

mkdir ~/mytest

Change the group permission from your username to www-data

sudo chgrp www-data ~/mytest

Create the symlink to the web directory

sudo ln -s ~/mytest /var/www/mytest

Rejoice in an sqlite-capable directory (specifically located at http://localhost/mytest). Give it a test with the example here (but in this example remove the “unsigned” part of “unsigned primary key” first) or here.

Staypressed theme by Themocracy