7

请帮忙!我无法将 codeigniter 连接到 Oracle 我正在尝试将 Codeigniter 连接到 Oracle 11g,这是我的设置

Settings in database.php:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = "//localhost/";
$db['default']['username'] = 'xxxxxxx';
$db['default']['password'] = 'xxxxxxx';
$db['default']['database'] = 'orcl';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$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;

注意:我将 C:\instantclient_11_2 添加到环境变量到 PATH。

oracle port number:
oracle hostname: Home-pc
database name: orcl

只有当我运行我的 CodeIgniter 登录代码时,它才会显示此错误消息:

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: D:\xampp\htdocs\ci\system\database\DB_driver.php

Line Number: 124

但是当我运行一个简单的 php 代码时,我可以连接到 Oracle:

<?php
$conn = oci_connect("xxxxxx", "xxxxxx","");
if (!$conn) { 
   echo "Not connected!";
}
else
  echo "yahooooooooo!!!!!!!!!!";
?>

结果:哇哇哇哇!!!!!!!!!

4

4 回答 4

5

在您的配置的 database.php 中进行以下更改

$active_group = 'default';
$active_record = TRUE;

$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
        (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))';

$db['default']['hostname'] = $tnsname;
$db['default']['username'] = 'XXXXXX';
$db['default']['password'] = 'XXXXX';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$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;
于 2013-01-13T07:30:55.920 回答
2

默认更改为XE

$active_group = 'XE';
$active_record = TRUE;

$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
        (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))';

$db['XE']['hostname'] = $tnsname;
$db['XE']['username'] = 'XXXXXX';
$db['XE']['password'] = 'XXXXX';
$db['XE']['database'] = '';
$db['XE']['dbdriver'] = 'oci8';
$db['XE']['dbprefix'] = '';
$db['XE']['pconnect'] = TRUE;
$db['XE']['db_debug'] = TRUE;
$db['XE']['cache_on'] = FALSE;
$db['XE']['cachedir'] = '';
$db['XE']['char_set'] = 'utf8';
$db['XE']['dbcollat'] = 'utf8_general_ci';
$db['XE']['swap_pre'] = '';
$db['XE']['autoinit'] = TRUE;
$db['XE']['stricton'] = FALSE;
于 2014-11-12T09:46:31.770 回答
0

尝试执行此更改将主机名更改为http://localhost:1521:orcl 您的数据库名称orcl,默认情况下orcl是默认实例 ID。尝试创建新用户或数据库并将其更改为配置database

于 2012-12-28T04:15:46.960 回答
0

确保php_oci8_11g.dll已加载扩展程序php.ini

于 2013-06-06T15:07:21.957 回答