首页 > 数据库技术 > 详细

XAMPP(v1.83)中的PHP(v5.5.15)访问SQLServer2014

时间:2015-12-27 21:45:45      阅读:376      评论:0      收藏:0      [点我收藏+]
驱动安装:

1. 下载SQLServer的微软官方PHP驱动,http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

2. 安装SQLSRV31.EXE文件,也就是解压缩
3. 将文件(线程安全)php_pdo_sqlsrv_55_ts.dllphp_sqlsrv_55_ts.dll拷贝到\xampp\php\ext中
4. 修改\xampp\php\php.ini文件,在[PHP]下增加
    extension=php_pdo_sqlsrv_55_ts.dll
    extension=php_sqlsrv_55_ts.dll
5. 重启动计算机(可能非必需)
 
SQLSRV 函数 
编码转换:网页编码UTF-8
方法一:连接时指定字符集
   $conInfo=array(‘Database‘=>$database,‘UID‘=>$uid,‘PWD‘=>$pwd, ‘CharacterSet‘=>‘UTF-8‘);  
   $link=sqlsrv_connect($serverName,$conInfo);   
方法二:访问时使用iconv手动转换
  写入SQL Server时转换编码到GB2312
      iconv(‘utf-8‘, ‘GB2312//IGNORE‘, ‘要写入数据库的字符串‘));
  读取SQL Server字符串时转换编码到UTF-8
      iconv(‘GB2312‘, ‘utf-8//IGNORE‘, ‘数据库返回来的字符串‘));
 
PDO 函数 
编码转换:网页编码UTF-8,无需转换, PDO::SQLSRV_ENCODING_UTF8为缺省编码
数据库连接示例:
$c = new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");
$c = new PDO("sqlsrv:Server=localhost,1521;Database=testdb", "UserName", "Password");
connect to a MS SQL Server database on a specified port 1521。 
 
和MySQL比速度慢很多

XAMPP(v1.83)中的PHP(v5.5.15)访问SQLServer2014

原文:http://www.cnblogs.com/-mrl/p/5080797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!