$THIS == a real life website by Jonny Nail // life + code

class.db.php

This is my standalone database class that performs all of the basic generic functions you might need when building a database driven website. Generally this just makes life easier and I find this class is a good clean starting point for building your 'watch out world' web app.

First things first, let's make a fresh config 'ini' file. I call mine crunksauce.ini because the word 'crunksauce' is funny. Crunk. Sauce.

[database]
host = "localhost"
user = "username"
pass = "password"
dbname = "some_database"

..and now the star of the show...

Some notes:

1. If possible to store this class and the ini file in the server level ABOVE the webroot that would be recommended, just so people can't browse to the file in any possible way. Nanna always said - "you can never have enough security". If you change the placement of the ini file relative to this class you will (obvs) need to update the path in the parse_ini_file function.

2. The quote method might need to changed for certain servers as it seems as though (through some painful trial and error) that different set-ups handle slashes differently. Argh.

3. The debug method is just for testing purposes, simply dumping out an array so you can read it. Never leave home without this one.

Usage

include("class.db.php");
$db = new Db;
$res = $db->results("SELECT * FROM craig_mack WHERE wackness!=0");
$db->debug($res);
Go Home