install PHP DLL first:
https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx
CodeIgnitor: 2.2
SQL SERVER: SQL SERVER 2008 R2
PHP: 5.4
Web Server: Apache
/application/config/database.php $db['default']['hostname'] = '.\SQLEXPRESS'; $db['default']['username'] = 'sa'; $db['default']['password'] = 'XXXXXXX'; $db['default']['database'] = 'YYYYYYY'; $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;
//system/database/drivers/sqlsrv/sqlsrv_driver.php
LINE 121 – 124
function db_select() { return $this->_execute('USE [' . $this->database.']'); }
//application/models/brand_model.php (testing model)
class Brand_model extends CI_Model { private $table_name = ""; public function __construct() { $this->load->database(); $this->table_name = "[Brand]"; } public function get(){ $query = $this->db->get($this->table_name); return $query->result_array(); } }
發佈留言