Board logo

標題: CI連接mssql的正確方法 [打印本頁]

作者: admin    時間: 2011-11-7 23:01     標題: CI連接mssql的正確方法

有人說不用mssql,因為是微軟的,我也執這個想法,哈哈。
但是有的專案需要啊,.NETer懶得寫介面,要從mssql中取資料,怎麼辦?
還是分享吧。

config中database:

$db['sqlserver']['hostname'] = "192.168.70.59\SQLEXPRESS";
$db['sqlserver']['username'] = "sa";
$db['sqlserver']['password'] = "sa";
$db['sqlserver']['database'] = "LandwindV2";
$db['sqlserver']['dbdriver'] = "mssql";
$db['sqlserver']['dbprefix'] = "";
$db['sqlserver']['pconnect'] = FALSE;
$db['sqlserver']['db_debug'] = FALSE;
$db['sqlserver']['cache_on'] = FALSE;
$db['sqlserver']['cachedir'] = "";
$db['sqlserver']['char_set'] = "utf8";
$db['sqlserver']['dbcollat'] = "utf8_general_ci";

php打開mssql擴展,更新ntwdblib.dll至2000.80.194.0
單php更新有時不成功,將apache中ntwdblib.dll同時更新至2000.80.194.0

控制器中寫法(建議手動連接,節省資源):
    function mssqltest(){
        $DB_2 = $this->load->database('sqlserver', TRUE);
        $query = $DB_2->query("select * from SysUser")->result_array();
        
        dump($query);
    }


OK




歡迎光臨 Discuz! Board (http://tako.dacom.tw/) Powered by Discuz! 7.2