Welcome Guest, Not a member yet? Register   Sign In
CI and SQL SERVER 2005 and MS ADODB not ADOdb
#3

[eluser]riza_nurhadi[/eluser]
ok im posting again..
for CodeIgniter 1.6.3/4 and SQL SERVER 2005 as database
here we go
now im succeed creating an adodb driver in codeigniter
so you can autoload the driver and its not as a library.

im still using php COM class to connect to database
Code:
function db_connect()
    {
         $conn = new COM("ADODB.Connection") or die("Cannot start ADO");
         $conn->Open("Provider=SQLOLEDB; Data Source=".$this->hostname.";
         Initial Catalog=".$this->database."; User ID=".$this->username."; Password=".$this->password."");
        return $conn;
    }
and you can use config/database.php to call or autoload the SQL SERVER 2005 database like this
Code:
//@system/config/database.php
$db['default']['hostname'] = "dbserver";
$db['default']['username'] = "sa";
$db['default']['password'] = "iforgot";
$db['default']['database'] = "mydb2";
////here is the driver
$db['default']['dbdriver'] = "adodb";
////end here is the driver
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

as you see im using dbdriver "adodb" not mssql or sqlsrv.
to use this you need to forge the codeigniter code.

first of all you need to create new dbdriver
create new folder system\database\drivers and rename it "adodb"

then create 4 files inside adodb folder
- adodb_driver.php
- adodb_forge.php
- adodb_result.php
- adodb_utility.php

so youll have some thing like this
Code:
system/database/adodb/adodb_driver.php
                     /adodb_forge.php
                     /adodb_result.php
                     /adodb_utility.php
                /mssql/
                /mysql/
                blablabla

you can copy the driver from mssql driver[located @ system\database\drivers\mssql]
and rename it to adodb the filename and the class name..well that is what i do


but first i add something to DB_driver.php and DB_result.php.
i only change the query function and result_array function just because this is the only CodeIgniter function that i use

the change that i made in DB_driver is only at function query
here is the change for DB_driver [located @ system\database\DB_driver.php]
Code:
///.....bla bla bla
// this is @ system\database\DB_driver.php
function query($sql, $binds = FALSE, $return_object = TRUE){
///.....bla bla bla
    // Load and instantiate the result driver    
        $driver         = $this->load_rdriver();
        $RES             = new $driver();
        $RES->conn_id    = $this->conn_id;
        $RES->result_id    = $this->result_id;
        $RES->num_rows    = $RES->num_rows();
        ///just add something here for adodb driver
        $RES->dbdriver = $this->dbdriver;

///.....bla bla bla
}
///.....bla bla bla
the change that i made in DB_result is only at function result_array
here is the change for DB_result [located @ system\database\DB_result.php]
Code:
/// ......bla bla bla
function result_array()
    {
    // no change here the change is down there
        if (count($this->result_array) > 0)
        {
            return $this->result_array;
        }
        // In the event that query caching is on the result_id variable
        // will return FALSE since there isn't a valid SQL resource so
        // we'll simply return an empty array.
        // no change here
        if ($this->result_id === FALSE OR $this->num_rows() == 0)
        {
            return array();
        }
        $this->_data_seek(0);    
/////BEGIN this is the change i made
        if($this->dbdriver != 'adodb'){
        while ($row = $this->_fetch_assoc())
        {
            $this->result_array[] = $row;
        }
        } else {
        $this->result_array = $this->_fetch_assoc();
        }
/////END this is the change i made        
        return $this->result_array;
    }
    /// ......bla bla bla

ok next post is the 4 code inside adodb folder
- adodb_driver.php
- adodb_forge.php
- adodb_result.php
- adodb_utility.php


Messages In This Thread
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 04-21-2009, 10:32 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 04-22-2009, 06:18 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-06-2009, 03:07 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-06-2009, 03:23 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-06-2009, 03:31 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-06-2009, 03:39 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-06-2009, 11:54 AM
CI and SQL SERVER 2005 and MS ADODB not ADOdb - by El Forum - 05-12-2009, 03:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB