从Codeigniter连接到IBM DB2

时间:2013-09-04 09:42:38

标签: php codeigniter pdo db2 odbc

我之前从未使用过DB2。我正在尝试从codeigniter连接。我在数据库配置文件中使用了以下设置:

$db['default']['hostname'] = 'ipAddress';
$db['default']['port'] = 'portNumber';
$db['default']['username'] = 'uname';
$db['default']['password'] = 'pword';
$db['default']['database'] = 'myDBName';
//$db['default']['dbdriver'] = 'pdo';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

并抛出以下错误:

Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\archive\system\database\DB_driver.php

同样,我是DB2的新手,所以如果我需要安装额外的东西(我假设驱动程序已经包含在我最新的CI下载中)或者我需要定义一个dsn(请告诉我怎么做如果我需要的话,请让我知道,非常感谢你的帮助。

2 个答案:

答案 0 :(得分:2)

是的,您需要安装IBM Data Server Client软件包,或至少安装Runtime Client。从http://www-01.ibm.com/support/docview.wss?uid=swg27016878

下载相应的驱动程序

本手册介绍了如何configure DB2 access from a PHP application

答案 1 :(得分:0)

您需要添加与hostname参数的完整连接,如下面的代码

$active_group = 'default';
$active_record = FALSE;
$db['default']['hostname'] = "driver={IBM db2 odbc DRIVER};Database=DBNAME;hostname=localhost;port=50000;protocol=TCPIP;" . "uid=username; pwd=password";
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'DBNAME.SCHEMANAME';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;