【问题标题】:CodeIgniter 3.1.10 : Cannot connect to remote database by DSN using ODBCCodeIgniter 3.1.10:无法通过 DSN 使用 ODBC 连接到远程数据库
【发布时间】:2019-03-20 19:52:10
【问题描述】:

如上所述,我在使用 CodeIgniter 3.1.10 中的 ODBC 驱动程序通过 DSN 连接到远程数据库时遇到问题。 DSN 已在 ODBC 数据源管理器中创建。当我想将系统从 CodeIgniter 2.2.3 更新到 3.1.10 时出现问题。

它实际上适用于 CodeIgniter 2.2.3,代码如下:

$db['default']['hostname'] = "myDSN";
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = 'myDatabase';
$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;

但它在下面显示错误:

当前未加载数据库驱动程序

当我在 CodeIgniter 3.1.10 上尝试使用与以下代码相同的设置时:

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

但是在 CodeIgniter 3.1.10 中,当我使用以下代码手动连接到数据库时,连接成功:

$dbconn=odbc_connect("myDSN", "", "");

if(!$dbconn)
{
    die("Could not connect Adaptive Server Anywhere: ".odbc_errormsg(). odbc_error());
} else {
    echo "connection success";
}

那么,既然使用手动代码可以连接,有没有人指导我如何使用CodeIgniter 3.1.10中的数据库代码连接成功?

【问题讨论】:

    标签: php codeigniter odbc sqlanywhere


    【解决方案1】:

    在对此进行了大量研究之后 - 我相信问题不在于 ODBC 元素,而在于您没有自动加载数据库库。该错误与 ODBC 无关,但正如我在这里发现的那样:Codeigniter: Database driver is not currently loaded 是因为我不相信您已经自动加载了数据库。

    【讨论】:

      猜你喜欢
      • 2019-11-13
      • 2011-12-27
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多