phpstudy 连接sqlserver数据库

phpstudy 连接sqlserver数据库 参考 http://my.oschina.net/u/733393/blog/110141

第一步:下载sqlsrv扩展

打开http://www.microsoft.com/en-us/download/details.aspx?id=20098   下载 SQLSRV20.EXE

下载地址:http://pan.baidu.com/s/1eQ7u3kA

解压将三个文件解压后的内容


修改配置文件php.ini


php extendsion 为 nts 则将对应的上图中绿框的文件复制到 对应php/ext的目录下


php.ini部分配置

extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_mongo.dl
extension=php_sqlsrv.dll
extension=php_pdo_sqlsrv.dll

mssql.secure_connection = on


sqlsrv扩展、(Microsoft Drivers for PHP for SQL Server
依赖Microsoft SQL Server 2008 R2 Native Client 故需要安装

打开http://msdn.microsoft.com/en-us/library/cc296170%28SQL.90%29.aspx 选择 Download the X86 package下载,点击安装即可

下载地址:http://pan.baidu.com/s/1o6kd7To


Microsoft SQL Server 2008 R2 Native Client下载

http://www.microsoft.com/zh-CN/download/details.aspx?id=27596

云盘下载地址 http://pan.baidu.com/s/10HBCM


thinkphp连接代码

<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller {
	public function index() {
		$config = array (
				'db_type' => 'pdo', //采用pdo方式连接
				'db_user' => '***',
				'db_pwd' => '***',
				'db_charset' => 'utf8',
				'DB_DSN' => 'sqlsrv:Server=120.209.149.134;Database=gpsbase',
		);
		$where ["TerminalID"] = "14100087049";
		$m = M ( "Warn", "", $config )->where ( $where )->select ();
		dump ( $m );
	}
}


阅读更多

没有更多推荐了,返回首页