Solution to the problem that php cannot connect to mssql: 1. Modify the authentication mode; 2. Modify and confirm the account password; 3. Enable the account's permission to access the database.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if php cannot link to mssql?
php is usually used together with mysql database, but when developing some enterprise applications, because the original application of the enterprise uses MSSQL, php must be connected to SQL Server.
This is also a Big pitfalls, let’s talk about 3 common reasons why using php to connect to SQL Server fails...
Before connecting php to mssql, you need to install the sqlsrv extension first. This is also a lot of pitfalls.
php code to connect to SQL Server is as follows
//$serverName = "localhost"; $serverName = "127.0.0.1"; $connectionInfo = array( "Database"=>"qinziheng", "UID"=>"sa", "PWD"=>"123456"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.<br />"; }else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true)); }
1. The authentication mode is wrong
SQL Server has two authentication modes,
1-1) windows authentication mode,
means using the account or domain account in the windows system.
1-2) Some SQL Server authentication modes are also called SQL Server and Windows authentication modes.
Use the account created by the SQL Server database.
It is recommended to use the second type. SQL Server authentication mode.
2. The account password is incorrect
When PHP connects to the msql database, it involves the windows system account, domain account and SQL Server database account. For friends who have connected once, I don’t know which one to choose.
When we use PHP to develop the mssql database, we use the SQL Server identity authentication mode in 1-2. The connection is successful using the SQL Server database account, but the domain account connection fails.
The relationship between the Windows system account and the SQL Server database account is just like the relationship between the Linux system account and the MySQL database account in Linux. You cannot use the www user in Linux to log in and connect to the MySQL database.
3. Unauthorized access to the database
Although your account password is correct, the PHP connection to mssql still fails. The reason is that your account does not have permission to access the database. At this time, you need to log in to SSMS (SQL Server Management Studio), authorize the user, or add the user to the corresponding security group.
There is another possible reason for the errorThe above three reasons are often encountered in development. If your PHP and SQL Server are installed on different hosts On the other hand, there is another possibility that SQL Server does not allow remote connections and access.
Recommended learning: "
PHP Video TutorialThe above is the detailed content of What to do if php cannot link to mssql. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft