search
HomeBackend DevelopmentPHP ProblemHow to connect to sqlserver with PHP

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 "链接成功";
        }}

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools