...
PHP

关于tp5连接sqlserver数据库的一些整理,php7.3连接sqlserver数据库

业务需求要使用SqlServer数据库,网上查了很多资料,说起来也不是很难,本文做个整理,方便以后查阅。

一、php配置

我呢用的是php7.3的版本,框架是TP5,操作系统是windows10,需要下载7.3的sqlsrv的扩展库。

sqlsrvPHP扩展库下载地址:https://github.com/Microsoft/msphpsql/releases

下载对应的包,我这里下载7.3版本的。




1.png

下载好了解压到php根目录的ext文件夹中

2.png

修改php.ini配置,添加下面两句:

extension=php_sqlsrv_73_nts.dll
extension=php_pdo_sqlsrv_73_nts.dll

现在就算基本配置好了php对SqlServer的支持,但是先别得意还有问题。


二、TP5配置

接下来我们来tp5数据库配置文件 datebase.php 修改配置:

// 数据库类型
 'type'              => 'sqlsrv',
  // 服务器地址
'hostname'          => '127.0.0.1',
 // 数据库名
 'database'          => 'dataname',
// 用户名
'username'          => 'sa',
 // 密码
'password'          => '123456',
// 端口
'hostport'          => '1433',


三、错误处理

接着试着访问网站出现了如下错误信息:

SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64

别慌!!!

这个是因为少了一个驱动,msodbcsql.msi!!!

下载地址:https://www.microsoft.com/zh-tw/download/confirmation.aspx?id=36434

下载地址2:https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=36434

下载完后安装就可以了,此时访问一切正常!


参阅文档:

PHP7.3连接sqlserver2008:https://www.it610.com/article/1296696248555872256.htm

thinkphp连接sql server:https://blog.csdn.net/a1234name/article/details/90405284

关于thinkPHP5+sqlserver配置:http://www.thinkphp.cn/topic/53119.html

Linux crontab 计划任务,定时执行任务方法 Composer 国内镜像大全
biu biu biu
常用sql server sql语句 常用正则表达式语句 ASCII码对照表 http状态码解释 js/php身份证算法