2013-01-11 114 views
10

所以我使用訪問數據庫(* mdb)。 這是我的代碼,併成功連接:Codeigniter使用ms訪問數據庫

$db['test']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\blabla.mdb'; 
$db['test']['username'] = ''; 
$db['test']['password'] = ''; 
$db['test']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\blabla.mdb'; 
$db['test']['dbdriver'] = 'odbc'; 
$db['test']['dbprefix'] = ''; 
$db['test']['pconnect'] = TRUE; 
$db['test']['db_debug'] = TRUE; 
$db['test']['cache_on'] = FALSE; 
$db['test']['cachedir'] = ''; 
$db['test']['char_set'] = 'utf8'; 
$db['test']['dbcollat'] = 'utf8_general_ci'; 
$db['test']['swap_pre'] = ''; 
$db['test']['autoinit'] = TRUE; 
$db['test']['stricton'] = FALSE; 

,現在我想用ACCESSDB從其他計算機。 這個accessdb(* mdb)已被共享,我製作了地圖網絡驅動器(Z :)。

所以我改變主機名和數據庫,但它的失敗:

$db['test']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=Z:\blabla.mdb'; 
$db['test']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=Z:\blabla.mdb'; 

我嘗試這:

$db['test']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=\\10.0.0.107\share\blabla.mdb'; 
$db['test']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=\\10.0.0.107\share\blabla.mdb'; 

但它仍然錯誤:

Unable to connect to your database server using the provided settings. 
Filename: D:\folder\folder\system\database\DB_driver.php 

Line Number: 124 

,甚至我嘗試連接php ,這是結果php using msaccess

+0

可能會有幫助:http://stackoverflow.com/questions/178860/code-igniter-cakephp-and-ms-access – Fionnuala

+0

@Remou已經閱讀之前,使這個問題:( – Belajar

+1

@duskwuff我不想要,但它的用戶請求 – Belajar

回答

2

問題是默認的IIS IUSER無法通過網絡共享訪問文件。 的變通辦法在此處詳細說明:http://support.microsoft.com/kb/207671

我強烈推薦使用SQL Server(速成版,如果沒有別的)比訪問文件 - 你會得到一個很大的改進的經驗+你將能夠更容易地遷移,因爲該網站如果需要擴展。

0

你是否檢查過對該文件的讀寫權限?如果您的php應用程序在IIS上運行,那麼您的IIS用戶帳戶將需要具有對該文件的讀/寫權限,而不是用於登錄到計算機的用戶帳戶。

+0

這應該是一個評論,而不是一個答案? – ZombieSpy

+0

是的,我讀了這麼多的時間,它仍然沒有工作,我使用Apache,我已經檢查讀/寫訪問mdb文件..... – Belajar

1

我發現此線程的問題類似於:http://ellislab.com/forums/viewthread/93160/。說,你應該嘗試加載從控制器手動加載ODBC驅動程序:

$this->load->database(); 
$this->db->dbdriver = 「odbc」; 

它還說,由於某種原因,數據庫配置不可用ODBC驅動程序:

system/database/drivers/odbc/odbc_driver.php

所以,你也可以必須進入並手動加載數據庫配置。

0

檢查你的PHP程序在哪個用戶下運行。用PHP列出一個目錄內容來檢查。考慮到運行你的PHP的用戶也可能沒有你在你自己的用戶名下創建的Z的映射。

0

許多搜索(沒有自提解決方案工作)之後,我發現了一個不同的解決方案,在某些MS Access數據庫的,你只能在連接字符串中使用雙斜槓(而不是在數據庫路徑)連接:

$db['test']['hostname'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\path\\to\my.mdb'; 
$db['test']['username'] = ''; 
$db['test']['password'] = ''; 
$db['test']['database'] = 'Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\path\to\my.mdb'; 
$db['test']['dbdriver'] = 'odbc'; 
$db['test']['dbprefix'] = ''; 
$db['test']['pconnect'] = TRUE; 
$db['test']['db_debug'] = TRUE; 
$db['test']['cache_on'] = FALSE; 
$db['test']['cachedir'] = ''; 
$db['test']['char_set'] = 'utf8'; 
$db['test']['dbcollat'] = 'utf8_general_ci'; 
$db['test']['swap_pre'] = ''; 
$db['test']['autoinit'] = TRUE; 
$db['test']['stricton'] = FALSE; 

不知道是什麼原因,因爲我能夠使用單斜槓和雙斜槓連接一些Access數據庫(相同的服務器,相同的文件夾,相同的Access版本)不起作用,認爲這是一個愚蠢的笑話,在IE上工作:-(

0

此作品:

$db['access']['hostname'] = 'DNS name created by me'; // or ip address 
$db['access']['username'] = ''; 
$db['access']['password'] = ''; 
$db['access']['database'] = ''; 
$db['access']['dbdriver'] = 'odbc'; 
$db['access']['dbprefix'] = ''; 
$db['access']['pconnect'] = FALSE; 
$db['access']['db_debug'] = TRUE; 
$db['access']['cache_on'] = FALSE; 
$db['access']['cachedir'] = ''; 
$db['access']['char_set'] = 'utf8'; 
$db['access']['dbcollat'] = 'utf8_general_ci'; 
$db['access']['swap_pre'] = ''; 
$db['access']['autoinit'] = TRUE; 
$db['access']['stricton'] = FALSE; 
1
$db['second']['hostname'] = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:/wamp/www/ket_noi_access/test1.mdb";//C:\wamp\www\ket_noi_access 
$db['second']['username'] = "ADODB.Connection"; 
$db['second']['password'] = "xxxxx"; 
$db['second']['database'] = "C:/wamp/www/ket_noi_access/test1.mdb"; 
$db['second']['dbdriver'] = "odbc"; 
$db['second']['dbprefix'] = ""; 
$db['second']['pconnect'] = TRUE; 
$db['second']['db_debug'] = TRUE; 
$db['second']['cache_on'] = FALSE; 
$db['second']['cachedir'] = ""; 
$db['second']['char_set'] = "utf8"; 
$db['second']['dbcollat'] = "utf8_general_ci"; 
$db['second']['swap_pre'] = ''; 
$db['second']['autoinit'] = TRUE; 
$db['second']['stricton'] = FALSE; 

代碼

function __construct(){ 
    parent::__construct(); 
    $this->legacy_db = $this->load->database('second',true); 
} 
function LayDanhSach(){ 
    $this->legacy_db->select('*'); 
    $this->legacy_db->from('ban'); 
    $query = $this->legacy_db->get(); 
    $kq=$query->result(); 
    $this->legacy_db->close(); 
    //$this->db->close(); 
    return $kq;  
} 

$this->load->model("ban_model"); 
$ds=$this->ban_model->LayDanhSach(); 
$st="This is demo multi database and msaccess connect <br>";   
$st.=json_encode($ds); 
$this->data['content']=$st;//json_encode($ds);//echo json_encode($ds); 
$this->load->view('index_view2',$this->data,false);