One of the most powerful aspects of Snappad are it’s modules. Adding functionality to your project simply by downloading the proper module provides limitless possibilities.This tutorial is intended to teach you how to add a module to your Snappad project. As the Romans used to say Ex exempium scientia. Or as the not yet dead language of English would say “From Example, Knowledge.”
Introducing the Database Module
The module we will be installing for use is the database module, commonly called db.mod. The database module is intended to provide access to a mySQL database for a Snappad project, future improvements may allow connection to SQLite or PostgreSQL… But that is for the future, this tutorial is for the now.
Installing the Database Module
Installing db.mod is an easy, three step process.
- Create a folder called ‘db’ in your projects “modules” directory.
- Download the most recent db.mod.php and db.class.php files from the stable repository and place them in the db folder.
- Configure the module by putting the following code into your config.inc.php file:
$config->db = new config;
$config->db->host='server';
$config->db->username='username';
$config->db->password='password';
$config->db->name='database_name';
Using the Database module
Using the Database module is also easy. Simply include the line “$snappad->load_module(’db’);” in whichever part of your project needs the database connection. This then creates an instance of the db class called $db. Now simply putting $result = $db->query(’SELECT * FROM table’) will execute that MySQL query.
For more information on using the database module, visit the Snappad Wiki.
