Solution to the error when php connects to sqlserver: 1. Open php.in and remove the comment symbol of extension=php_mssql.dll; 2. Find the ntwdblib.dll file; 3. Run SQL Server Configuration Manager and set it Just use the port.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if there is an error when connecting to sqlserver with php?
About the problem of php connecting to sqlserver
Some points that should be paid attention to when using php to connect to sqlserver2000
1. Configure php
a. Open php.in and remove the comment symbol of extension=php_mssql.dll.
b. Open php.in. If your program and database are on the same server, please change mssql.secure_connection = Off to on. If they are on two servers, please change it to off, otherwise it will report Errors such as "Login failed for user (Null)".
c. Copy php_mssql.dll to the directory specified by extension_dir in php.in or the system system32 directory. (php_mssql.dll is included in the compressed installation package of php).
2. Pay attention to the ntwdblib.dll file
a. Find the ntwdblib.dll file in the system32 directory of the server where sqlserver2000 is installed, check its version through the properties, and then use this as the standard Overwrite the corresponding files in the php directory of the program server.
b. The corresponding files under apache2/bin also need to be overwritten! (Many people can't connect because they didn't notice this step, and so did I)
After completing the above steps, you need to restart apache.
Note: In actual use, it was found that if you manually install php to iis through a php compressed file, you must restart the machine and not just iis.
3. Configure sqlserver
a. Run SQL Server Configuration Manager: SQL Server Configuration Manager, open Protocols
b. Allow named pipes "named pipes" and " tcp/ip"
c. Right-click "tcp/ip" and open the Properties tab "IP addresses"
d. Fill in 1433## in the TCP dynamic port "TCP Dynamic Ports"
#e. Restart SQL Server---------------------------------- --------------- ---------------------------------- ----------4. Use the following method to connect to MS SQL Server 2005: The code is as follows:<?php //链接数据库 $conn=mssql_connect('localhost','sa','123456'); mssql_select_db('gu_dde',$conn); //query语句 $Query="select * from dde_top"; $AdminResult=mssql_query($Query); //输出结果 $Num=mssql_num_rows($AdminResult); for($i=0;$i<$Num;$i++) { $Row=mssql_fetch_array($AdminResult); echo($Row[1]); echo("<br/>"); } ?>
PHP Video Tutorial"
The above is the detailed content of What to do if there is an error connecting php to sqlserver. For more information, please follow other related articles on the PHP Chinese website!