下载Sql Server PHP扩展
Microsoft Drivers for PHP for SQL Server
https://github.com/Microsoft/msphpsql/releases/tag/v5.2.0-RC
https://github.com/Microsoft/msphpsql/tags(全部连接)
下载ODBC驱动
Microsoft® ODBC Driver 13.1 for SQL Server
https://www.microsoft.com/en-us/download/details.aspx?id=53339
下载的文件放入php7.2.3\ext
Wamp切换到PHP7.2.3
编辑PHP.ini配置文件
加入扩展
extension=php_sqlsrv_72_ts.dll
extension=php_pdo_sqlsrv_72_ts.dll
退出Wamp重新打开用phpinfo()查看
ThinkPHP 5 测试
database.php
// 数据库类型 'type' => 'sqlsrv', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'AdventureWorks2008R2', // 用户名 'username' => 'sa', // 密码 'password' => 'Sa123',
<?php // 控制器 namespace app\index\controller; use think\Db; use think\Controller; class Index extends Controller { public function index() { $Store = Db::name('sales.store')->field('BusinessEntityID,Name')->paginate(10); $this->assign('list',$Store); return $this->fetch(); } }
<!-- 视图 --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="static/css/bootstrap.css"> <title>Document</title> </head> <body style="margin-top: 30px"> <div class="container"> <table class="table table-bordered"> <thead> <tr> <th>BusinessEntityID</th> <th>Name</th> </tr> </thead> <tbody> {volist name='list' id='Store'} <tr> <td>{$Store.BusinessEntityID}</td> <td>{$Store.Name}</td> </tr> {/volist} </tbody> </table> {$list->render()} </div> </body> </html>