2012-12-23 171 views
6

請幫忙!我可笨無法連接到Oracle 我試圖笨連接到Oracle 11g中,這裏是我的設置將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環境變量設置路徑。

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

只有當我跑我的笨登錄代碼它顯示此錯誤消息:

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 

但我可以連接到Oracle,當我運行一個簡單的PHP代碼,如:

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

結果: yahooooooooo !!!!!!!!!!

+0

你試過留下主機名,就像'localhost'一樣。沒有斜槓? – dakdad

回答

0

嘗試這樣做改變 改變主機名http://localhost:1521:orcl 你給出數據庫名爲orcl,默認情況下orcl是默認實例ID。 嘗試創建新用戶或數據庫並將其更改爲配置database

+0

謝謝阿賓,這可能是一個很好的解決方案,但對不起,我沒有機會嘗試它。我卸載了我正在使用的Oracle完整版本並將其替換爲快速版本,它與我的設置一起工作 – zallexy

3

在你配置的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; 
+1

感謝Prakash,實際上這可能已經奏效。我通過卸載oracle完整版並用快速版替換它來解決了這個問題。它使用相同的設置 – zallexy

0

確保php_oci8_11g.dll擴展裝入php.ini

+0

是的,擴展程序被加載。 – zallexy

1

變化默認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;