简体   繁体   中英

How to connect odbc database using codeigniter?

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => 'tes',
    'hostname' => 'localhost',
    'username' => '',
    'password' => '',
    'database' => 'tes',
    'dbdriver' => 'odbc',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

When I run the program there is an error:

" Message: Call to undefined method CI_DB_odbc_driver::select() Filename: models/m_city.php"

m_city.php file:

<?php

class m_city extends CI_Model
{
    function get_all($where = array())
    {
        $this->db->select('Name,Population');
        $this->db->where($where);
        $this->db->limit('50');
        $query = $this->db->get('City');
        return $query->result_array();
    }
} 

I already made dsn name on odbc. the name of dsn is "tes".

If you use "Mysql" then follow the following instructions. Please put database username and database password in the following:

$active_group = 'default';
    $query_builder = TRUE;

    $db['default'] = array(

    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => '',//Put database username
    'password' => '',// put database password
    'database' => 'tes',
    'dbdriver' => 'odbc',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
    );

After complete this save the page and open the page 'autoload.php' under the config folder. There search "$autoload['libraries']" option. Put the following

$autoload['libraries'] = array('database');

If you use PDO, PostgreSQL, Oracle then see the following links:

https://www.codeigniter.com/user_guide/database/configuration.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM