< Portability Class Constructor   (Previous) Table of Contents (Next)   DSN's >

Connection Script

<?php

/**
 * Establishes the PEAR::DB and Portability objects
 *
 * Choose the DBMS by setting the <var>$dbms</var> variable in your
 * script before including this file.  Remember that <var>$dbms</var>
 * must refer to a valid element name inside the <var>$dsns</var> array.
 *
 * @package    Portability
 * @author     Daniel Convissor <danielc@analysisandsolutions.com>
 * @copyright  2002-2005 The Analysis and Solutions Company
 * @license    http://www.analysisandsolutions.com/software/license.txt  Simple Public License
 * @link       http://www.analysisandsolutions.com/presentations/portability/
 * @see        dsns.inc
 */

require_once 'dsns.inc';

if (empty($dbms) || !array_key_exists($dbms, $dsns)) {
    echo '$dbms is unset or does not match an element in $dsns.';
    exit;
}

require_once 'DB.php';

$options = array(
    'debug'       => 2,  // on live sites, comment out this line
    'portability' => DB_PORTABILITY_ALL,
);

$db =& DB::connect($dsns[$dbms], $options);
if (DB::isError($db)) {
    if ($options['debug'] >= 2) {
        die($db->getUserInfo());
    } else {
        die($db->getMessage());
    }
}

$p =& new Portability($db);

if (isset($callback)) {
    $db->setErrorHandling(PEAR_ERROR_CALLBACK, 'error_handler');
} else {
    $db->setErrorHandling(PEAR_ERROR_DIE);
}