[mottle] SQL Driver

Serge Grondin SGrondin at csbf.qc.ca
Tue Aug 26 08:15:49 PDT 2003


Hi!,

I don't know what appened but the file didn't follow, here it is.

Serge Grondin a écrit :
> 
> Hi!
> 
> I just installed Mottle and the driver for SQL is not there.  I created
> the minimum driver.  It do nothing except silence the error:  "Mottle is
> not properly configured".  :)  My PHP skill is very limited but I can
> try to find little bug here and there.  :)
> 
> I hope to be more usefull in the developpement of that module.  And
> thanks for developping this functionnality.
> 

-- 
Serge Grondin
Technicien en Informatique
Commission Scolaire des Bois-Francs
Tel. bur.:   (819) 758-6453, poste 2920
e-Mail bur.: SGrondin at csbf.qc.ca
-------------- next part --------------
<?php
/**
 * Mottle storage implementation for PHP's PEAR database abstraction layer.
 *
 * Required values for $params:<pre>
 *      'phptype'       The database type (e.g. 'pgsql', 'mysql', etc.).
 *      'hostspec'      The hostname of the database server.
 *      'protocol'      The communication protocol ('tcp', 'unix', etc.).
 *      'username'      The username with which to connect to the database.
 *      'password'      The password associated with 'username'.
 *      'database'      The name of the database.
 *      'table'         The name of the tasks table in 'database'.</pre>
 *      'charset'       The database's internal charset.
 *
 * Required by some database implementations:
 *      'options'       Additional options to pass to the database.
 *      'tty'           The TTY on which to connect to the database.
 *      'port'          The port on which to connect to the database.
 *
 * The table structure can be created by the scripts/drivers/mottle.sql
 * script.
 *
 * $Horde: 
 *
 * @author  
 * @version 
 * @since   Mottle 0.1
 * @package mottle
 */
class Mottle_Driver_sql extends Mottle_Driver {

    /** Hash containing connection parameters. */
    var $_params = array();

    /** Handle for the current database connection.
        @var object DB $db */
    var $_db;

    /** Boolean indicating whether or not we're connected to the SQL server. */
    var $_connected = false;

    /**
     * Constructs a new SQL storage object.
     *
     * @param string $user      The user who owns these tasks.
     * @param array  $params    A hash containing connection parameters.
     */
    function Mottle_Driver_sql($user, $params = array())
    {
        $this->_user = $user;
        $this->_params = $params;
    }

    /**
     * Disconnect from the SQL server and clean up the connection.
     *
     * @return boolean     true on success, false on failure.
     */
    function _disconnect()
    {
        if ($this->_connected) {
            $this->_connected = false;
            return $this->_db->disconnect();
        }

        return true;
    }

    /**
     * Attempts to open a persistent connection to the SQL server.
     *
     * @return boolean    True on success; exits (Horde::fatal()) on error.
     */
    function _connect()
    {
        if (!$this->_connected) {
            Horde::assertDriverConfig($this->_params, 'storage',
                array('phptype', 'hostspec', 'username', 'database', 'charset', 'table'));

            /* Connect to the SQL server using the supplied parameters. */
            require_once 'DB.php';
            $this->_db = &DB::connect($this->_params,
                                      array('persistent' => !empty($this->_params['persistent'])));
            if (is_a($this->_db, 'PEAR_Error')) {
                Horde::fatal($this->_db, __FILE__, __LINE__);
            }

            /* Enable the "portability" option. */
            $this->_db->setOption('optimize', 'portability');

            $this->_connected = true;
        }

        return true;
    }

}


More information about the mottle mailing list