Messing with PHP and SQLite

Started working on a project in PHP. PHP was one of the first CS courses I took and at the time I was still learning how to learn languages so my notes weren’t good. Actually the project I was working on was a system to dynamically display my notes online from a source directory and using syntax highlighting.

This project is giving me an opportunity to create the PHP notes I need and also to refresh myself with the language. It’s such a cool language especially now at v.7.

So I kind of got sidetracked on my project and ended up spending a whole day figuring out how to use PHP with SQLite3. Here is some code. This page creates a sample SQLite3 database and then does a basic query.

For this to run you need both sqlite3 and the php-sqlite3 extension installed.

I deliberately left in some commented-out lines after I implemented other/better ways to accomplish the same thing.

You can see the script in action here.

Credit to the excellent official PHP documentation for SQLite3 and the many informative comments.

Also major credit to the extremely great book Learning PHP, MySQL, & JavaScript by Robin Nixon.

Special thanks to the totally kickass WordPress plugin Crayon Syntax Highlighter!