- Install PHP: 5.3 is recommended. (All .dll files related to 5.4 won’t work!)
http://www.php.net/downloads.php - Download Microsoft Drivers: Do not use 3.0, only 2.0 dll files will work!
http://www.microsoft.com/en-us/download/details.aspx?id=20098 - Copy drivers to “ext” folder (default in php 5.3, and can be changed in php.ini)
- Update php.ini (Use text editor or PHP Manager)
e.g. extension=php_pdo_sqlsrv_53_nts_vc9.dll (vc6 won’t work!) - Restart IIS
- Check PDO support in phoinfo(): “sqlsrv” should be in “enable” list.
- Connection String: sqlsrv:Server=19x.1xx.1xx.1xx;Database=lab
Here is my environment: Windows 7 + IIS 7 + SQL Server 2008 R2, PHP 5.3
Believing in latest version from MS is my fault.
Reference:
- http://www.ucamc.com/e-learning/computer-skills/146-php-sqlsrv.html
- http://www.yiiframework.com/forum/index.php/topic/18946-how-to-connect-mssql-database/
- http://www.php.net/manual/en/ref.pdo-sqlsrv.php
- http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php
- http://www.yiiframework.com/forum/index.php/topic/42723-could-not-find-driver-sqlsrv/
10/7/2014 Update
Reference:
- http://j796160836.pixnet.net/blog/post/32652509-%5Bphp%5D-php-5.4-(for-windows)%E4%B9%8B%E5%BE%8C%E7%89%88%E6%9C%AC%E9%80%A3%E6%8E%A5microsoft-sql-s
- http://msdn.microsoft.com/en-us/library/cc296170.aspx
- http://www.microsoft.com/en-us/download/details.aspx?id=20098
- Install sqlsrv extension in different windows servers (Very detailed):
http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html - For Codeigniter: http://www.kaweb.co.uk/uncategorized/mssql-server-2005-and-codeigniter/
- Complete Codeigniter for sqlsrv: (Replace files in /database/drivers/sqlsrv/)
http://www.manjustudio.com/2013/01/09/codeigniter-mssql-sqlsrv/
File: codeIgniter1 - Insert and Update UTF-8 into MSSQL (Need to revise driver):
http://stackoverflow.com/questions/22981997/insert-update-utf8-string-sql-server-codeigniter
1234567891011121314151617181920212223242526function _make_unicode($value){if(is_string($value) && $value!="NULL")return "N".$value;elsereturn $value;}function _insert($table, $keys, $values){foreach($values as $index => $value){$values[$index] = $this->_make_unicode($value);}return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";}function _update($table, $values, $where){foreach($values as $key => $val){$valstr[] = $key." = ".$this->_make_unicode($val);}return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);}
Settings in PHP Manager:
Sample Code:
1 2 3 4 5 6 7 8 9 10 |
$serverName = "[server name]"; //serverName\instanceName $connectionInfo = array( "Database"=>"[DB name]", "UID"=>"[account]", "PWD"=>"[password]"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); } |