2013-10-18 37 views
2

我見過很多帖子,但沒有實際的工作。有人可以提供一個乾淨/清晰的方式來連接Codeigniter與Mac上的MS SQL Server嗎?這是很高的水平,但我還沒有看到明確證明這一點的解決方案。謝謝一堆!如何將codeigniter連接到SQL服務器?

回答

0

我已經做到了這一點,在你application/config/database.php把下面:

// This address is valid if you're on the same domain as the server: 
// If not, you can put the ip address or url here as well. 
$db['default']['hostname'] = 'DBComputerName\SQLEXPRESS'; 

// if you need a non default port uncomment and edit 
//$db['default']['port'] = '5432'; 

$db['default']['username'] = 'databaseUsername'; 
$db['default']['password'] = 'databasePassword'; 
$db['default']['database'] = 'DatabaseName'; 
$db['default']['dbdriver'] = 'sqlsrv'; 
$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; 

我知道怎麼折騰,這是作爲一個忠告,不是所有的活動記錄功能的工作或按預期工作,這是由於許多SQL服務器怪癖。

我建議切換大部分的活動記錄查詢到:$this->db->query();

PS如果我沒有記錯,MSSQL沒有用戶名預配置,你需要創建一個用戶名,並允許從外部DB訪問子網。

請參閱本,以創建數據庫用戶:
http://technet.microsoft.com/en-us/library/aa337545.aspx
並允許訪問:
http://support.webecs.com/KB/a868/how-do-i-configure-sql-server-express-to-allow-remote.aspx

0

我用的是PDO驅動程序......這對我的作品:

$db['mssql']['hostname'] = 'sqlsrv:server=myserverIP;database=mydb;encrypt=true;trustservercertificate=true'; 
    $db['mssql']['username'] = 'myun'; 
    $db['mssql']['password'] = 'mypw'; 
    $db['mssql']['database'] = 'mydb'; 
    $db['mssql']['dbdriver'] = 'pdo'; 
    $db['mssql']['dbprefix'] = ''; 
    $db['mssql']['pconnect'] = TRUE; 
    $db['mssql']['db_debug'] = TRUE; 
    $db['mssql']['cache_on'] = FALSE; 
    $db['mssql']['cachedir'] = ''; 
    $db['mssql']['char_set'] = 'utf8'; 
    $db['mssql']['dbcollat'] = 'utf8_general_ci'; 
    $db['mssql']['swap_pre'] = ''; 
    $db['mssql']['autoinit'] = TRUE; 
    $db['mssql']['stricton'] = FALSE; 
+0

我同意你應該必須工作 –