您的位置:首页 > 编程语言 > PHP开发

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

2015-12-27 20:46 736 查看
驱动安装:
1. 下载SQLServer的微软官方PHP驱动,http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

2. 安装SQLSRV31.EXE文件,也就是解压缩
3. 将文件(线程安全)php_pdo_sqlsrv_55_ts.dll和php_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比速度慢很多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: