Roman Law db progress
Started writing the DB backend for Roman Law, and had to learn a lot of new stuff. I always use the PEAR abstraction layer for DB work, so that we could shift data between mySQL, PostgreSQL or Oracle if we needed to, but I couldn't get it working. I also couldn't get any useful PHP error messages out of Lettuce. I eventually discovered that I need to override two settings in the PHP config in order to get error reporting to work properly:
error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('html_errors', '1');
The third line just makes the errors more readable in the browser.
Once that was sorted out, we discovered that DB.php
(the PEAR DB library I'm used to using) wasn't installed. Greg got the sysops to sort that out, which they did immediately. Then I started looking at the latest documentation, and discovered that DB
is now deprecated; we're supposed to be using the new MDB2
classes. This required a bit more reading, but it turns out that MDB2 has some useful features, including a factory()
method which prepares a connection to the DB but doesn't actually create it until you use it, and the prepare()
method, which allows you to put up some barriers against SQL injection at the same time as improving speed a little by pre-caching some queries. There's definitely a lot more to learn about this.
I got connections working, and wrote some utility functions for retrieving data from a table in the form of HTML <option>
elements, then I wrote one specific function for adding a new row to the db and getting back (if appropriate) the amended list of option <elements>
. This works fine, but it can be streamlined and generalized; I'll do that next week.