CakePHP: Database connection "Sqlite" is missing, or could not be created

Just downloaded 2.1.1 stable to read a SQLite database.

There’s a nice diagnostics page to welcome any developer, except it complained about my database config:

Database connection "Sqlite" is missing, or could not be created.

So I thought it might’ve been a missing driver, or something, so I looked in lib/Cake/Model/Datasource/Database:

-rw-rw-r-- 1 kzhiwei kzhiwei 20K 2012-03-25 18:30 Mysql.php
-rw-rw-r-- 1 kzhiwei kzhiwei 25K 2012-03-25 18:30 Postgres.php
-rw-rw-r-- 1 kzhiwei kzhiwei 16K 2012-03-25 18:30 Sqlite.php
-rw-rw-r-- 1 kzhiwei kzhiwei 23K 2012-03-25 18:30 Sqlserver.php

Everything looked fine to me, except that naggy error. It turns out additional stuff is required for PHP to talk to SQLite. If you’re on Oneiric Ocelot (11.10), you’re in luck. The package name is “php5-sqlite”, so you can just use a shell to:

sudo apt-get install php5-sqlite -y
sudo /etc/init.d/apache2 restart

Once that is done, use ‘:memory:’ for the database param, to make sure that the server setup is OK.

Lastly, adjust the filename of the database file; e.g. mine is ‘/app/webroot/trac.db’, so I simply use ‘trac.db’. Once this is done, you may encounter another error:

Database connection "SQLSTATE[HY000] [14] unable to open database file" is missing, or could not be created.

This is due to a permissions problem, so check if the www-data group owns webroot, trac.db. It should like:

drwxr-xr-x 6 kzhiwei www-data 4.0K 2012-04-25 10:46 .
-rw-rw---- 1 kzhiwei www-data 12M 2012-04-24 18:45 trac.db

#cakephp, #sqlite, #ubuntu

Sorting a numeric array of numbers

When called upon, I couldn’t even write out a working version, but this one works.