I configured a new server today. The configuration is IIS php. When running, I found an error when php connected to the remote mssql database. The error code is as follows:
Warning: mssql_connect(): Unable to connect to server:
Thinking about it, it was all fine before, so what happened? Later, I searched online 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 didn’t need to use mssql on the new server, but now I have no choice but to install it. Yes, after installing mssql there will be no problem.
I was thinking, what would happen if it was Apache PHP on Linux? It is impossible to install mssql, haha, I am dizzy.
Below is an article I found.
php configuration:
Set as follows in the php.ini file and find
;extension=php_mssql.dll remove the semicolon in front
Find extension_dir = d:extension
Your php.ini may not contain d:extension
Change the path to php_mssql.dll under the extensions directory under the PHP installation directory. If you have not moved it to another place (assuming that your PHP installation path is d:php)
Just change it to extension_dir=d:phpextensions
Then restart 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 whether the database host variable settings are correct!!!
I checked the variable settings of the host over and over again, and there were no problems with those settings. I browsed through the web and found the following clues:
php.com information:
I am trying to connect to SQL Server 2000 from PHP
I bumped to the following warning:
Warning: mssql_connect(): Unable to connect to server: SERVERPortal
.......on line 5
on line 5 there is:
$db_connect = mssql_connect('SERVERPortal', '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 hours ,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 problems 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, and it was ntwdblib.dll
that caused the trouble.
The main function of ntwdblib.dll is to provide sql server connection service.
The PHP version I use is 4.3.9. 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 Overwrite all files under dlls to 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 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. Use square brackets [ ]
for the name of the database.
You can do it by bracketing it. If 123bbs is rewritten as [123bbs], there will be no problem. In addition, if your database name conflicts with the reserved words in SQL Server, this situation will also occur. 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 a day, the harvest was still great. Posting it now will save brothers who encounter the same problem from taking some detours.