aBlog2 currently comes with code for working with either a mySQL database server (mySQL_datalib.php) or sqlite3 (sqlite_datalib.php). You select which of these you will use during installation during installation.
It is, however, possible to write interfaces to other database systems and plug them into your system. To do this you need to create a set of database interface routines and then point to the file containing them at installation time. Since aBlog2 expects to use SQL your database software must either be able to deal with SQL or your functions will have to translate from SQL to whatever your database understands. Fortunately, aBlog2 doesn’t use any particularly complex SQL statements. You can look at the aBlogXajaxFunctions.php file to see what types of SQL statements you have to deal with.
The first thing to do is to create a php file with the appropriate routines. These routines will have available a set of defined constants created at installation time and loaded into the configuration file. These are,
DB_SERVER – the address of your database server, if you are using one
DB_USER – the name of a user with an account of the database server
DB_PASSWORD – the password associated with the DB_USER
DB_DATABASE – the database on the server to use. TheDB_USER must have permission to create and populate tables in this database.
PREFIX–the prefix to add before standard table names that make them unique for a particular instance of aLogin.
Within the file you need to define the following functions,
dl_dbInit() – This function, which takes no parameters, does whatever is necessary to establish a connection to, or open access to, a database. This will usually require the use of the defined values. It returns true on success and false on failure.
dl_get_single_record($query) – This function takes a single parameter in the form of a string containing a SQL select statement. It queries the database and returns the first record returned in the form of an associative array with the names of the fields functioning as the array keys. It is used when either only a single record should match the query or when looking for a value that would be constant for all matching records. It returns false on failure.
dl_get_mysql_array($query) – This function takes a single parameter in the form of a string containing a SQL select statement. It queries the database and returns the all the returned records in the form of an array of associative arrays with the names of the fields in the database functioning as the keys to the associative array. It returns false on failure.
dl_insert_record($query) – This function takes a single parameter in the form of a string containing a SQL insert statement. It inserts the data into the database and returns the id of the inserted record. The returned id is unique for each record.
dl_update_record($query) – This function takes a single parameter in the form of a string containing a SQL update statement. It updates the database with the provided data. Whatever is returned by the database is passed back to the calling function.
dl_run_command($query) - This function runs any query and passes the result back to the calling function. In most cases it will be identical to dl_update_record.
In general, assuming your database speaks SQL, you can take either mysql_datalib.php or sqlite_datalib.php and use them as the basis of your code.
Once you have the file defined and loaded into aBlog2 folder you can point to it during aBlog2 installation.
If you do write an interface to another database, we would appreciate getting a copy so we can distribute it with future versions of aBlog2.