PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Framework/DB/ADODB.php

https://github.com/shupp/Framework
PHP | 99 lines | 45 code | 9 blank | 45 comment | 5 complexity | d9043d52850a377ceee8281b791c68f6 MD5 | raw file
 1<?php
 2
 3/**
 4 * Framework_DB_ADODB 
 5 * 
 6 * Framework Driver for ADODB or ADODBLite
 7 * 
 8 * PHP Version 5.1
 9 * 
10 * @package    Framework
11 * @subpackage Framework_DB
12 * @author     Bill Shupp <hostmaster@shupp.org> 
13 * @copyright  2008 Bill Shupp
14 * @uses       Framework_DB_Common
15 * @license    BSD http://www.opensource.org/licenses/bsd-license.php
16 * @link       http://adodb.sourceforge.net/
17 * @link       http://adodblite.sourceforge.net/
18 */
19
20require_once 'Framework/DB/Common.php';
21
22/**
23 * Framework_DB_ADODB 
24 * 
25 * Framework Driver for ADODB or ADODBLite
26 * 
27 * @package    Framework
28 * @subpackage Framework_DB
29 * @author     Bill Shupp <hostmaster@shupp.org> 
30 * @author     Joe Stump <joe@joestump.net>
31 * @copyright  2008 Bill Shupp
32 * @uses       Framework_DB_Common
33 * @license    BSD http://www.opensource.org/licenses/bsd-license.php
34 * @link       http://adodb.sourceforge.net/
35 * @link       http://adodblite.sourceforge.net/
36 */
37class Framework_DB_ADODB extends Framework_DB_Common
38{
39    /**
40     * Create a singleton of ADODB or ADODBLite;  This driver works for 
41     * both.  Just specify the correct directory in 
42     * config->db->options->adodbDir.
43     * The directory in which adodbDir resides in must be in your
44     * include_path.
45     *
46     * @access public
47     * @throws Framework_DB_Exception on failure
48     * @return object                 Instance of ADODB[Lite] connected to the DB
49     */
50    public function singleton()
51    {
52        if (!is_null(parent::$db) && 
53            parent::$db instanceof ADOConnection) {
54            return parent::$db;
55        }
56
57        // Manually include files, ADODB does not follow naming conventions
58        if (empty($this->options->adodbDir)) {
59            throw new Framework_DB_Exception(
60                'Error: you must set $config->db->options->adodbDir'
61            );
62        }
63        $path = (string)$this->options->adodbDir . DIRECTORY_SEPARATOR;
64        if ((!include_once $path . 'adodb-exceptions.inc.php') ||
65            (!include_once $path . 'adodb.inc.php')) {
66            throw new Framework_DB_Exception(
67                'Error: could not include ADODB files'
68            );
69        }
70
71        // Connect
72        try {
73            parent::$db = ADONewConnection($this->dsn);
74        } catch (Exception $error) {
75            throw new Framework_DB_Exception(
76                $error->getMessage(), $error->getCode()
77            );
78        } 
79
80        // Fetch Modes
81        $fetchModes = array(
82            'ADODB_FETCH_DEFAULT' => ADODB_FETCH_DEFAULT,
83            'ADODB_FETCH_NUM'     => ADODB_FETCH_NUM,
84            'ADODB_FETCH_ASSOC'   => ADODB_FETCH_ASSOC,
85            'ADODB_FETCH_BOTH'    => ADODB_FETCH_BOTH
86        );
87
88        $fetchMode = ADODB_FETCH_ASSOC;
89        if (isset($this->options->fetchMode)&&
90            isset($fetchModes[(string)$this->options->fetchMode])) {
91            $fetchMode = $fetchModes[(string)$this->options->fetchMode];
92        }
93
94        parent::$db->SetFetchMode($fetchMode);
95        return parent::$db;
96    }
97}
98
99?>