New Sado Version 1.1 released! Easily add ORM to your applications using our Sado Library

Sado Bootstrap File

The Sado bootstrap file "sado.bootstrap.php" is a file that loads and initializes the necessary elements that Sado uses to operate. The bootstrap file is located in: lib/Sado/sado.bootstrap.php

Environment settings

First, set the location of the Sado library directory. This is done using the "dir_sado_lib" variable: $dir_sado_lib = dirname(__FILE__) . '/';Note: include the trailing slash "/" at the end of the directory.

Or you could use a static directory location: $dir_sado_lib = '/var/www/myproject/lib/Sado/';
Next, we need to include the "SadoFactory" class: // include SadoFactory class
require_once $dir_sado_lib . 'core/SadoFactory.php';

Autoloading

In this section autoloading can be turned on or off. What is autoloading? Autoloading means that all the Sado library classes will be autoloaded, which saves code by not have to do "requre_once(...)" a ton of times. To turn autoloading on make sure this line exists: SadoFactory::registerAutoload($dir_sado_lib);If another autoloader is already present and Sado should not autoload its own classes then turn off autoloading by commenting out this line: // SadoFactory::registerAutoload($dir_sado_lib);And add this directory to your other autoloader: $dir_sado_lib . "core/"

Sado Configuration

In this section we simply load the Sado configuration file (this is required): SadoFactory::confFile($dir_sado_lib . 'sado.conf.php');

Register Sado Instances

Here is where we setup out database connections. First, setup a database connection by entering your database location and credentials: // register instance 1
SadoFactory::registerInstance(SadoFactory::DRIVER_MYSQLI)
->host('localhost') // add location of DB, this can be localhost or IP address
->username('app') // DB username
->password('pass00') // DB password
->database('test') // DB name
->name('First DB Connection') // title used for DB (useful for logging/debugging)
->schemaFile($dir_sado_lib . 'sado.schema.php'); // location of Sado schema file
This is simple. Sometimes (not very often) you might use more than one database connection, which can be an advanced topic. This is where you can add more database connections as required by your application. Here is an example of a second database connection: // register instance 2
SadoFactory::registerInstance(SadoFactory::DRIVER_MYSQLI)
->host('localhost')
->username('app2')
->password('pass01')
->database('test2') // a different database
->name('Second DB Connection')
->schemaFile($dir_sado_lib . 'sado.schema.2.php'); // very important to use a different schema file
Now our second connection can be accessed from Sado classes and subclasses with the instance ID of 2.