本篇文章主要介紹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”