Home  >  Article  >  Backend Development  >  What to do if php fails to connect to mssql

What to do if php fails to connect to mssql

藏色散人
藏色散人Original
2021-12-31 10:04:142226browse

Solution to the failure of php to connect to mssql: 1. Find extension=php_mssql.dll in the php.ini file and remove the preceding semicolon; 2. Copy the php_mssql.dll file to "c:/windows/ system32/" directory; 3. Restart iis.

What to do if php fails to connect to mssql

The operating environment of this article: windows7 system, PHP5 version, DELL G3 computer

What should I do if php fails to connect to mssql?

Solution to PHP's inability to connect to the MSSQL database:

php database sql server extension sqlserver server

I received a question today. When I accessed the data of sqlserver2000 on the platform environment of php5 iis6 mysql5, I found an error when connecting php to the remote mssql database. The error code is as follows:

Warning: mssql_connect(): Unable to connect to server:

Think about it, it was no problem before, what happened? Later, I searched on the Internet and found an article, only to find out that the server needs to install mssql in order to use php to connect to mssql. Originally, I did not need to use mssql on the new server, but now I have no choice but to extend it. After extending mssql, there will be no problem.

Extension method:

1. Find

in the c:/windows/php.ini file; extension=php_mssql.dll and remove the semicolon in front

Find

;extension_dir = "./" Change the extension library directory to the php library directory, such as: extension_dir = "c:/php/ext"

2. Copy the php_mssql.dll file to the c:/windows/system32/ directory

3. Restart iis.

The following is an article found.

php configuration:

Set as follows in the php.ini file, find

;extension=php_mssql.dll Remove the semicolon in front

Find extension_dir = d:/extension/

Your php.ini may not be d:/extension/

Change it to php_mssql.dll under the extensions directory under the php installation directory, where Path, if you have not moved it elsewhere (assuming your php installation path is d:/php)

Change it to extension_dir=d:/php/extensions/

Then re- Start the web server

This is easy to do, but after completing such settings, it still cannot be connected. The error message is as follows:

MS SQL Server database connection error! Please check the database host Are the variable settings correct!!!

I checked the variable settings of the host over and over again, and there was no problem with those settings. I looked through the web and found the following clues:

php.com资料:
I am trying to connect to SQL Server 2000 from PHP
I bumped to following warning:
Warning: mssql_connect(): Unable to connect to server: SERVER/Portal
....... on line 5
on line 5 there is:
$db_connect = mssql_connect('SERVER/Portal', 'sa', 'my_passwd');
I did the following
1.enabled php_mssql.dll extension in PHP.ini
2.every dll is in proper place(System32 or PHP folder),including ntwdblib.dll
I search lots of profile throught web ,but no one give me proper answer to resolve it.
after a few hour ,I found the problem was caused by
ntwdblib.dll ,which version is 7.00.839 ,when I replaced old ntwdblib.dll with the new
ntwdblib.dll ,which version is 8.00.194 ,all problem are solved.
We had some, read A LOT, of problems with MSSQL under Windows 2003.
We had 2 the same windows, php, php-ini, everything machines but only one could connect.
Unable to connect was the error message.
Finnaly we checked the version of ntwdblib.dll and the one distributed with PHP was 7.00....
and the version of the one on the SQL Server install was 8.00.... so we copied this one in
the php and apache dir and it worked.

The problem was found in this way. The trouble was caused by ntwdblib.dll

The main function of ntwdblib.dll is to provide sql server connection service.

The PHP version I use is 5.25. In the windows/system32/ of the server where it is installed, I found that the version of the ntwdblib.dll file is 2000.2.8.0. This version supports SQL Server 7.0, because When installing PHP, all files under dlls will be overwritten into the system

directory, so when I use it to connect to sql server 2000, of course I will be unable to connect.

Later, I found out that the version of ntwdblib.dll was 2000.80.2039.0 on a server where sql server 2000 was installed normally. I copied this file to overwrite the previous version. After restarting the server, everything was normal. .

Supplement: If the database name starts with a number, it will also prompt that it cannot be opened. At this time, it is very simple. Enclose the name of the database in square brackets [ ]. For example, 123bbs is rewritten as [ 123bbs] There is no problem. In addition, this situation will also occur if your database name conflicts with the reserved words in SQL Server. You can also solve it by using square brackets.

Finally, the problem of PHP being unable to correctly connect to sql server 2000 was finally solved. Although it took most of the day, the harvest was still great. Now I post it to let brothers who encounter the same problem. Take fewer detours.

Finally, if your target MSSQL computer is equipped with a firewall, please open port 1433, especially for windows xp systems!

After reading the above information, I asked a friend who installed sqlserver2000 to pass the "ntwdblib.dll" file to me. My local test was successful, but when I uploaded it to the server, the info() did not have the mssql extension. It was already loaded. Why is it not there? There is basically no difference between the php.ini file and the local one. It just cannot be expanded. Everything is normal locally.

Finally, it was found that there was still a problem with the version of "ntwdblib.dll", and I found a higher version of "ntwdblib.dll" to replace it.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php fails to connect to mssql. 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