Home >Backend Development >PHP Tutorial >Things to note when connecting PHP to SQLSERVER (with dll file download)_PHP tutorial

Things to note when connecting PHP to SQLSERVER (with dll file download)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:18:251229browse

Environment:
- Apache 2.2.6
- PHP 5.2.5
- SQL Server 2005
- Windows XP SP2
Steps:
1. First press The usual method is to configure PHP5 to connect to MS SQL Server
2. Download the correct version of ntwdblib.dll (2000.80.194.0). Pay attention to this version number. If it is not this version of the dll, it will not work. It took me a long time to discover this at the beginning. Question, remember. . .
Address: http://www.jb51.net/dll/ntwdblib.dll.html
3. Cover apache2.2.6binntwdblib.dll
4. Cover php5.2.5ntwdblib.dll
5 . Run SQL Server Configuration Manager: SQL Server Configuration Manager, open Protocols
6. Allow named pipes "named pipes" and "tcp/ip"
7. Right-click "tcp/ip" and open Properties Tag "IP addresses"
8. Fill in 1433 in the TCP Dynamic Ports "TCP Dynamic Ports"
9. Restart SQL Server, Apache and PHP
Connect to MS SQL Server 2005 using the following method:
mssql_connect ('localhost,1433', USERNAME, PASSWORD);

Configure php

1. Open php.in and remove the comment symbol of extension=php_mssql.dll.
2. Open php.in and change mssql.secure_connection = Off to on.
3. 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 php compressed installation package).
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.
4. You need to ensure that there is ntwdblib.dll under php or system32. Check the properties to ensure that its version is 8.00.194 instead of 7.0...
Other settings
If php apache Sql Server2000 is on the same machine, there will be basically no problem accessing it.
If Sql Server2000 and PHP machines are separated, you need to confirm that the machine name of the machine where SQLServer is located can be pinged. If it cannot be passed, modify the hosts file under system32driversetc of the machine where PHP is located and add a line of the machine IP of the machine where SQLServer is located. The machine name of the machine.
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.
In order to connect php to sql2005, I found a lot of information on the Internet and put it in my csdn blog. At 3:05 in the evening, I finally solved it.
The problem of php connecting to sql2005 is now integrated and the FAQ is integrated. Above.

The tutorial I wrote earlier:

Configuring the system before connection:
1. Check the file php5.2.5ntwdblib.dll. By default, there is one below, which cannot be used. Connect and replace.
Download the correct version of ntwdblib.dll (2000.80.194.0), address: http://www.jb51.net/dll/ntwdblib.dll.html
2. Configure php
a , open php.in and remove the comment symbol of extension=php_mssql.dll.
b. Open php.in and change mssql.secure_connection = Off to on.
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).
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:

Copy the code The code is as follows:

/ /Link database
$conn=mssql_connect('localhost','sa','123456');
mssql_select_db('gu_dde',$conn);
//query statement
$Query= "select * from dde_top";
$AdminResult=mssql_query($Query);
//Output result
$Num=mssql_num_rows($AdminResult);
for($i=0;$i< ;$Num;$i++)
{
$Row=mssql_fetch_array($AdminResult);
echo($Row[1]);
echo("");
}
?>

Enter http://127.0.0.1/


5. FAQ:
1 Error:
Fatal error: Call to undefined function mssql_connect ()
Solution:
Use MSSQL_ series functions
To use these two, you need to set them in php.ini:
(1) To allow DCOM, you need to change the; in php.ini; Remove the semicolon ";" before com.allow_dcom=TRUE.
(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:AppServ5.2.6phpext".
(4) If the machine still reports an error saying that c:AppServ5.2.6phpextphp_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:AppServ5.2.6phpextphp_mssql.dll; c:AppServ5.2.6phpntwdblib.dll)
In addition, remember to restart the server after setting it up.
2.mssql_connect() Unable to connect to server
Confirm that the SQLServer2005 server is normal. Check that TCP/IP is enabled
and right-click to view the properties:
Is it enabled? Select Yes
After confirming that the server is correct , and then confirm whether the ntwdblib.dll file location is placed under c:windowssystem32
At the same time, make sure that the version of ntwdblib.dll file corresponds to the version of sqlserver:
The following is the corresponding relationship:
2.ntwdblib.dll The version is 2000.2.8.0, which corresponds to SqlServer2000 (this is based on online information and guesswork, 2000 has not been installed)
2.ntwdblib.dll The version is 2000.80.194.0, which corresponds to SqlServer2005 (this is proven by experiments that it can be used, I use a laptop 2005 is installed)
3.ntwdblib.dll version is 2000.80.2039, which corresponds to SqlServer2008 (this is a guess that 2008 is not installed)
6. Other questions:
If php apache Sql Server2000 are both on the same machine , access is basically no problem.
If Sql Server2000 and PHP machines are separated, you need to confirm that the machine name of the machine where SQLServer is located can be pinged. If it cannot be passed, modify the hosts file under system32driversetc of the machine where PHP is located and add a line of the machine IP of the machine where SQLServer is located. The machine name of the machine.
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.
Solve the problem as follows:
1. Download two files php_mssql.dll and ntwdblib.dll
php_mssql.dll If this is not copied to c:windowssystem32, it will easily occur
Pay attention to the version of this file ntwdblib2093.dll, otherwise it will be very frustrating later.
If your MSSQL database is 2000, the operations are basically the same.
Add a new server of win2003 server system. In the past, other servers used php5.0/5.1, and the database was SQL Server 2000; this time, we plan to install SQL Server 2005, php5.3.2; it is understood that the php5.3 version uses Microsoft's FastCGI mode, which is different from the traditional CGI mode adopts a more reasonable parsing process startup mode, which is 2 times faster than CGI; versions above PHP5.3 no longer support ISAPI mode.

After installing iis6 and ms sql server 2005, the entire installation process is
1. Install FastCGI;
2. Install php5.3.2;
3. Install SQL Server Driver for PHP 1.1 driver;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325522.htmlTechArticleEnvironment: - Apache 2.2.6 - PHP 5.2.5 - SQL Server 2005 - Windows XP SP2 Steps: 1. First, configure PHP5 to connect to MS SQL Server as usual. 2. Download the correct version of ntwdblib.dll (200...
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