php7.2鏈接Sqlserver2008 r2

下載Sql Server PHP擴展php

Microsoft Drivers for PHP for SQL Servercss

https://github.com/Microsoft/msphpsql/releases/tag/v5.2.0-RChtml

https://github.com/Microsoft/msphpsql/tags(所有鏈接)git

下載ODBC驅動github

Microsoft® ODBC Driver 13.1 for SQL Serversql

https://www.microsoft.com/en-us/download/details.aspx?id=53339數據庫

下載的文件放入php7.2.3\extbootstrap

Wamp切換到PHP7.2.3服務器

編輯PHP.ini配置文件php7

加入擴展

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>

相關文章
相關標籤/搜索