如何使用codeigniter连接odbc数据库?

时间:2018-05-12 02:25:57

标签: php 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
);

当我运行程序时出现错误:

  

"消息:调用未定义的方法CI_DB_odbc_driver :: select()文件名:models / m_city.php"

m_city.php文件:

<?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();
    }
} 

我已经在odbc上创建了dsn名称。 dsn的名字是&#34; tes&#34;。

1 个答案:

答案 0 :(得分:0)

如果您使用&#34; Mysql&#34;然后按照以下说明操作。 请将数据库用户名和数据库密码放在以下位置:

$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
    );

完成此操作后,保存页面并打开页面&#39; autoload.php&#39;在config文件夹下。搜索&#34; $ autoload [&#39; libraries&#39;]&#34;选项。请填写以下内容

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

如果你使用PDO,PostgreSQL,Oracle,那么请看以下链接:

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