1, Configuration apache+php5.3
2. Configure the SQL Server server and allow remote connections.
3, to http://www.microsoft.com/en-us/download/details.aspx?id=20098 download SQLSRV20.EXE, if it is php5.4,5.5, Download SQLSRV30.EXE or SQLSRV31.EXE, then extract the files to any directory, there is a description of the document to see if it matches your PHP version.
4, execute SQLSRV20.EXE Extract files to the specified directory, view phpinfo (), see your PHP compiler model and whether it supports multithreading and so on. The View field is "PHP Extension Build", My Is "api20090626,ts,vc9", so I will extract the files from the previous step Php_pdo_sqlsrv_53_ts_vc9.dll and Php_sqlsrv_53_ts_ Vc9.dll is placed in the Ext folder in the PHP installation directory. Note The selected file name contains "ts", "VC9". Do not select files that do not match.
5, modify php.ini, add
Extension=php_pdo_sqlsrv_53_ts_vc9.dll
Extension=php_sqlsrv_53_ts_vc9.dll
Restart Apache and check phpinfo () to make sure Apache has supported sqlsrv.
6, configuration CodeIgniter.
Configure the database connection information in the application\config\database.php.
$active _group= ' Default ';$active _record=TRUE;$db[' Default '] [' hostname '] = ' server IP ';$db[' Default '] [' username '] = ' user name ';$db[' Default '] [' password '] = ' password ';$db[' Default '] [' database '] = ' db name ';$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;
Can not write port $db[' default ' [' port '] =; default is 1433
Create a database class in Application\models.
<?PHPclassExpert_modelextendsCi_model {function__construct () {Parent::__construct ();} Public functionGetCount () {$sql= ' SELECT count (*) as Count from dbo. View_expert ';$query=$this->db->query ($sql );return $query->row ()Count;} Public functiongetRows () {$sql= ' Select Top ' from dbo. View_expert ';$query=$this->db->query ($sql );return $query-Result_array ();}}
Test in the application/controllers.
<? PHP class extends Ci_controller {publicfunction view () {$this->load->helper (' URL ' ); $this TRUE ); Var_dump ($this->expert_model->getcount ()); Var_dump ($this->expert_model->getRows ());}? >
Code igniter + PHP5.3 + SqlServer2008 configuration