How to connect to sqlserver with PHP

(*-*)浩
Release: 2023-02-23 22:50:02
Original
3719 people have browsed it

sqlserver

Also known as MSSQL, it is a relational database management system (DBMS) developed and promoted by Microsoft. The operating software can use "sqlserver"

How to connect to sqlserver with PHP

How does php connect to sqlserver?

First of all, it is clear that wampserver does not support connecting to sqlserver, so you have to download the driver to connect to sqlserver yourself. There are also PHP versions that are 5.3 or above, excluding 5.3

1) Download the Microsoft SQL Server PHP driver. (Recommended learning:PHP Programming from Beginner to Master)

With the Microsoft SQL Server PHP driver, PHP developers can access SQL Server databases. This type of driver relies on the Microsoft SQL Server ODBC driver to handle low-level communication with SQL Server. What I downloaded is 3.0, run the installation and extract it to the PHP extension directory ext,

2) Here I am using the PHP 5.4.45 version, so the driver to be used is

;sqlserver

extension=php_pdo_sqlsrv_54_ts.dll

extension=php_sqlsrv_54_ts.dll

3) The first connection may report an odbc driver error. I checked for a long time and it turns out that it still needs to be installed. sqlserver odbc driver source

Download and install directly

https://www.microsoft.com/en-us/download/confirmation.aspx?id=36434

4) Connection test code

public function index() { //echo phpinfo(); $serverName = "222.180.xxx.xx"; //数据库服务器地址 $uid = "bbapp"; //数据库用户名 $pwd = "bbapp2017"; //数据库密码 $connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>"rivermanage"); $conn = sqlsrv_connect($serverName, $connectionInfo); if( $conn == false){ echo "连接失败!"; var_dump(sqlsrv_errors()); exit; }else{ echo "链接成功"; }}
Copy after login

The above is the detailed content of How to connect to sqlserver with PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!