php 串連 SQL Server 2008

來源:互聯網
上載者:User
本篇文章主要介紹php 串連 SQL Server 2008,感興趣的朋友參考下,希望對大家有所協助。

PHP內建的MSSQL擴充php_mssql.dll是給SQL Server 2000用的,SQL Server 2000+的版本用微軟為PHP提供的第三方擴充:Microsoft SQL Server PHP 驅動程式,URL是:https://msdn.microsoft.com/library/dn865013.aspx ,下載版本參照以下(注意:如果是3.1+版本還需要下載安裝ODBC):


  • Version support for PHP is as follows
    For more detail and for supported operating systems, see System Requirements (Microsoft Drivers for PHP for SQL Server) .

    • Version 4.0 supports PHP 7.0+

    • Version 3.2 supports PHP 5.6, 5.5, and 5.4

    • Version 3.1 supports PHP 5.5 and 5.4

    • Version 3.0 supports PHP 5.4.

  • An Internet Information Services (IIS) Web server is required

  • Version 4.0 requires Microsoft ODBC Driver 11 or Microsoft ODBC Driver 13.

  • Versions 3.2 and 3.1 of the driver require Microsoft ODBC Driver 11 (or higher). You can download the Microsoft ODBC Driver 11 here.

  • Version 3.0 requires the x86 version of Microsoft SQL Server 2012 Native Client.

比如下載SQLSRV31.EXE檔案雙擊解壓得到N個*.dll檔案,根據php安裝目錄包含的類似“php5ts.dll”來使用對應的*.ts.dll或*.nts.dll,參考如下URL:https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx 。


配置:

把 php_sqlsrv_55_ts.dll 和 php_pdo_sqlsrv_55_ts.dll 一起拷貝到php安裝目錄的擴充目錄(ext)下,配置php.ini檔案:增加以下兩行:

extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll

重啟相關服務後用phpinfo測試是否安裝成功。


串連資料庫測試:

<?php$serverName = "MS-201703.....GD\SQLEX....."; //伺服器名稱,在 sql server management studio 的登入介面查看$uid = "sa"; //資料庫使用者名稱$pwd = "123"; //資料庫密碼$db  = "cart"; // 資料庫名$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>$db);$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn == false) {    echo "串連失敗!";    die( print_r( sqlsrv_errors(), true));}//執行有結果集的SQL語句$query = sqlsrv_query($conn, "select top 1 * from tb_goods");$row = sqlsrv_fetch_array($query) ;print_r($row);?>

相關推薦:

Windows平台如何?PHP串連SQL Server2008

php串連sql server資料庫

使用thinkphp串連sqlserver資料庫時提示“系統不支援:sqlsrv”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.