PHP connection to SQL Server 2008

Source: Internet
Author: User
Tags microsoft drivers for php for sql server management studio sql server management sql server management studio
This article mainly introduces the PHP connection SQL Server 2008, interested in the friend's reference, I hope to help you.

PHP's own MSSQL extension php_mssql.dll is for SQL Server 2000, the version of SQL Server 2000+ with third-party extensions provided by Microsoft for PHP: Microsoft SQL server PHP driver, The URL is: https://msdn.microsoft.com/library/dn865013.aspx, download version reference the following (note: If the 3.1+ version also needs to download the installation of 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 one or Microsoft ODBC Driver 13.

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

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

For example, download SQLSRV31.EXE file Double-click Extract to get n *.dll files, according to the PHP installation directory contains similar "Php5ts.dll" to use the corresponding *.ts.dll or *.nts.dll, 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 to the PHP installation directory extension directory (EXT), 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 related service, use Phpinfo to test if the installation is successful.


To connect to a database test:

<?php$servername = "MS-201703 ..... Gd\sqlex ... "; Server name, view $uid = "sa" in the Login interface of SQL Server Management Studio; Database user name $pwd = "123"; Database password $db  = "cart";//Database name $connectioninfo = Array ("UID" = = $uid, "PWD" = = $pwd, "database" = $db); $conn = Sqlsrv_connect ($serverName, $connectionInfo); if ($conn = = False) {    echo ' connection failed! ";    Die (Print_r (Sqlsrv_errors (), True));} Execute SQL statement with result set $query = sqlsrv_query ($conn, "select top 1 * from Tb_goods"), $row = Sqlsrv_fetch_array ($query);p Rint_r ($ro W);? >

Related recommendations:

How the Windows platform implements PHP connection SQL Server2008

PHP connection to SQL Server database

"System not supported: sqlsrv" When connecting to SQL Server database using thinkphp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.