Welcome Guest, Not a member yet? Register   Sign In
Updated ADODB Loader For CI
#1

[eluser]Obasi George[/eluser]
Good Day,

Found a ADODB Loader for CI on the web: http://www.ciforge.com/projects/adodb

I have updated it to work with 1.6.2, and it works just like it was adodb on its' own.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['adodb']['dsn']           = 'driver://username:password@hostname:port/databasename';
$config['adodb']['db_var']        = true;
$config['adodb']['debug']         = false;
$config['adodb']['show_errors']   = true;
$config['adodb']['active_record'] = false;

/* End of file adodb.php */
/* Location: ./system/application/config/adodb.php */

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class init_adodb
{
  function init_adodb()
  {
    if ( ! class_exists('ADONewConnection') )
    {
      require_once(APPPATH.'libraries/adodb/adodb.inc'.EXT);
      require_once(APPPATH.'libraries/adodb/adodb-error.inc'.EXT);
    }

    $this->obj =& get_instance();
    $this->_init_adodb_library();
  }

    function _init_adodb_library()
    {
        $db_var = false;
        $debug = false;
        $show_errors = true;
        $active_record = false;

        // try to load config/adodb.php
        // CI 1.4.0+
        if ($this->obj->config->load('adodb',true,true)) {
            $cfg = $this->obj->config->item('adodb','adodb');
            if (isset($cfg['dsn'])) {
                $dsn = $cfg['dsn'];
            }

            if (isset($cfg['db_var'])) $db_var = $cfg['db_var'];
            if (isset($cfg['debug'])) $debug = $cfg['debug'];
            if (isset($cfg['show_errors'])) $show_errors = $cfg['show_errors'];
            if (isset($cfg['active_record'])) $active_record = $cfg['active_record'];

        }

        if (!isset($dsn)) {
            // fallback to using the CI database file
            include(APPPATH.'config/database'.EXT);
            $group = 'default';
            $dsn = $db[$group]['dbdriver'].'://'.$db[$group]['username'].':'.$db[$group]['password'].'@'.$db[$group]['hostname'].'/'.$db[$group]['database'];
        }

        if ($show_errors) {
            require_once(APPPATH.'libraries/adodb/adodb-errorhandler.inc'.EXT);
        }

        // $this->obj is by reference, refers back to global instance
        $this->obj->adodb =& ADONewConnection($dsn);
        $this->obj->adodb->setFetchMode(ADODB_FETCH_ASSOC);

        if ($db_var) {
            // also set the normal CI db variable
            $this->obj->db =& $this->obj->adodb;
        }

        if ($debug) {
            $this->obj->adodb->debug = true;
        }

        if ($active_record) {
            require_once(APPPATH.'libraries/adodb/adodb-active-record.inc'.EXT);
            ADOdb_Active_Record::SetDatabaseAdapter($this->obj->adodb);
        }
    }

  /**     "Factory" function to get an ADOdb ActiveRecord object for a certain table name
   * Eg:
   *   $person =& ADOdb_Active_Record_Factory('person');
   * creates a class called "person" that extends ADOdb_active_record and returns an instance of it.
   * The class will use the ADOdb table-naming conventions, so the active record will use the 'persons' table
   * To override the table name:
   *   $person =& ADOdb_Active_Record_Factory('person', 'people');
   */
  function ADOdb_Active_Record_Factory($classname, $tablename = null)
  {
    // create the class
    eval('class '.$classname.' extends ADOdb_Active_Record{}');

    if ($tablename != null) {
      return new $classname($tablename);
    } else {
      return new $classname;
    }
  }
}

/* End of file init_adodb.php */
/* Location: ./system/application/libraries/init_adodb.php */

copy the adodb library to your applications\library\ folder.

load: $this->load->library('init_adodb');
usage: $this->db->[ ADODB FUNCTION ]
#2

[eluser]sikkle[/eluser]
Are you skilled enough to give to community a good resume about pros and cons of ADODB ?

thanks !
#3

[eluser]tmsajin[/eluser]
can you try to extend ci model with active record?
#4

[eluser]Unknown[/eluser]
I was having some problems with this till I read with calm the code and found the problem. In PHP5 objects are passed by reference so I changed a couple of lines:

From this:
Code:
$this->obj->adodb =& ADONewConnection($dsn);

To this:
Code:
$this->obj->adodb = ADONewConnection($dsn);


And from this:
Code:
$this->obj->db =& $this->obj->adodb;

To this:
Code:
$this->obj->db = $this->obj->adodb;
#5

[eluser]dcunited08[/eluser]
[quote author="sikkle" date="1211442345"]Are you skilled enough to give to community a good resume about pros and cons of ADODB ?

thanks ![/quote]

I have used it on another, non-CI project and found it to work quite well. It is fully extendable and customizable, covers many different kinds of databases and is pretty fast. I guess the biggest con would be another custom library to keep up to date. What exactly are you wanting to know?




Theme © iAndrew 2016 - Forum software by © MyBB