php connect to SQL Server 2008

墨辰丷
Release: 2023-03-25 20:28:01
Original
3599 people have browsed it

This article mainly introduces PHP to connect to SQL Server 2008. Interested friends can refer to it. I hope it will be helpful to everyone.

The MSSQL extension php_mssql.dll that comes with PHP is for SQL Server 2000. The SQL Server 2000 version uses the third-party extension provided by Microsoft for PHP: Microsoft SQL Server PHP driver. The URL is: https: //msdn.microsoft.com/library/dn865013.aspx. To download the version, refer to the following (Note: If it is version 3.1, you also need to download and install 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.
  • For example, download SQLSRV31. Double-click the EXE file to decompress it to get N *.dll files. Use the corresponding *.ts.dll or *.nts.dll according to the "php5ts.dll" contained in the PHP installation directory. Refer to the following URL: https://msdn. microsoft.com/en-us/library/cc296170(v=sql.105).aspx .


Configuration:

Copy php_sqlsrv_55_ts.dll and php_pdo_sqlsrv_55_ts.dll together to the extension directory (ext) of the PHP installation directory , configure the php.ini file: add the following two lines:

extension=php_sqlsrv_55_ts.dll

extension=php_pdo_sqlsrv_55_ts.dll


After restarting the relevant services, use phpinfo to test whether the installation is successful. .


Connection database test:

<?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);
?>
Copy after login
Related recommendations:

How to implement PHP connection on Windows platform SQL Server2008

php connects to sql server database

When using thinkphp to connect to sqlserver database, it prompts "The system does not support: sqlsrv"

The above is the detailed content of php connect to SQL Server 2008. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template