如何在Codeigniter上连接到Vertica Db

时间:2016-07-23 15:07:28

标签: php database codeigniter odbc vertica

我试图在Codeigniter框架上连接到Vertica数据库。

我可以使用以下代码手动连接到Vertica。

$conn = odbc_connect('verticaDSN', 'dbadmin', 'password') or die(odbc_errormsg());

但我无法使用Codeigniter进行连接。您可以在下面看到我的CI数据库配置。

/config/database.php:

$db['vertica'] = array(
    'dsn' => 'DSN=VerticaDSN;Server=10.10.118.5;Port=5433;Database=db_prod;UserName=dbadmin;',
    'hostname' => '10.10.118.5',
    'port' => 5433,
    'username' => 'dbadmin',
    'password' => 'password',
    'database' => 'db_prod',
    'dbdriver' => 'odbc',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => FALSE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

/controllers/myControl.php:

public function __construct() {
        parent::__construct();
        $this->load->model('mymodel');
    }

    public function index() {
        var_dump($this->mymodel->get_last_fifty());
    }

/models/Mymodel.php:

public function __construct() {
        parent::__construct();
        $this->load->database('vertica');
    }

    public function get_last_fifty() {
        $query = $this->vertica->query("SELECT * FROM table ORDER BY id DESC LIMIT 50");
        return $query->result();
    }

输出:

Fatal error: Call to a member function query() on a non-object

A PHP Error was encountered

Severity: Error

Message: Call to a member function query() on a non-object

Filename: models/Mymodel.php

Line Number: 11

Backtrace:

感谢您的帮助, 宽单峰

0 个答案:

没有答案