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 3.0 requires the x86 version of Microsoft SQL Server 2012 Native Client.
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.dllextension=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); ?>
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!