What to do if there is an error connecting php to sqlserver

藏色散人
Release: 2023-03-13 10:14:02
Original
2005 people have browsed it

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.

What to do if there is an error connecting php to sqlserver

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(&#39;localhost&#39;,&#39;sa&#39;,&#39;123456&#39;);
mssql_select_db(&#39;gu_dde&#39;,$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/>");
}
?>
Copy after login

You can see these functions and MySQL The functions are all corresponding and very convenient to use!

-------------------------------------------------- ----------------------------

5.FAQ Frequently Asked Questions:

1Error Report:

Fatal error: Call to undefined function mssql_connect()

Solution:

Use MSSQL_series functions

To use both of these, you need to configure php.ini Make settings:

(1) To allow DCOM, you need to remove the semicolon ";" before ;com.allow_dcom=TRUE in php.ini.

(2) To use MSSQL extension, you need to remove the semicolon ";" before ;extension=php_mssql.dll in php.ini. (Key)

(3) Confirm extension_dir is the correct path, take this machine as an example: extension_dir = "c:\AppServ\php5\ext".

(4) If the machine still reports an error saying that c:\AppServ\php5\ext\php_mssql.dll cannot be found but this file obviously exists.

Solution: Copy php_mssql.dll and ntwdblib.dll to the system directory \system32 and restart the test. .

(Note: The above two dll files are not in the same directory, mine is c:\AppServ\php5\ext\php_mssql.dll; c:\AppServ\php5\ntwdblib.dll)

Also copy ntwdblib.dll to the apache2/bin/ directory!

Also remember to restart the server after setting it up.

6. Other questions:

If php apache Sql Server2000 is on the same machine, there will be basically no problem accessing it.

If the Sql Server2000 and PHP machines are separated, you need to confirm that the machine name of the machine where the SQL Server is located can be pinged. If it cannot be passed, modify the hosts file under \system32\drivers\etc of the PHP machine and add a line. The machine IP of the machine where sqlserver is located. The machine name of the machine where sqlserver is located.

If you still cannot access it, you need to confirm whether the machine where php is located has a secret conversion to mdac. How about simply installing the sqlserver client.

Recommended learning: "

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template