Considerations for connecting PHP to SQLSERVER (dll file download included) _ PHP Tutorial

Source: Internet
Author: User
Tags sql server driver
Notes for connecting PHP to SQLSERVER (dll file download is included ). Environment:-Apache2.2.6-PHP5.2.5-SQLServer2005-WindowsXPSP2 steps: 1. first configure the PHP5 connection MSSQLServer2. download the correct version of ntwdblib. dll (200 environment:
-Apache 2.2.6
-PHP 5.2.5
-SQL Server 2005
-Windows XP SP2
Steps:
1. configure PHP5 to connect to ms SQL Server as usual
2. download the correct version of ntwdblib. dll (2000.80.194.0). Note that this version number does not work for this version of dll. it has been a long time since it started to discover this problem. remember...
Address: http://www.jb51.net/dll/ntwdblib.dll.html
3. overwrite apache2.2.6 \ bin \ ntwdblib. dll
4. overwrite php5.2.5 \ ntwdblib. dll
5. run SQL Server Configuration Manager: SQL Server Configuration Manager to enable Protocols.
6. allow named pipelines "named pipes" and "TCP/IP"
7. right-click "TCP/IP" to open the Properties tag "ip addresses"
8. enter 1433 in the TCP Dynamic port "TCP Dynamic Ports ".
9. restart SQL Server, Apache, and PHP
Connect to ms SQL Server 2005 using the following methods:
Mssql_connect ('localhost, 100', USERNAME, PASSWORD );

Configure php

1. open php. in and remove the annotation 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 system32 directory of the system. (Php_mssql.dll is included in the php compression installation package ).
After completing the preceding steps, restart apache.
Note: in actual use, if php is manually installed under iis through the php compressed file, the machine must be restarted, not just iis.
4. ensure that ntwdblib. dll is available in php or system32, and check the attribute to make sure that the version is 8.00.194 instead of 7. 0 ......
Other settings
If php apache SQL Server2000 is on the same machine, the access is basically normal.
If the SQL Server and php machines are separated, make sure that the machine name on which the SQL Server server is located can be pinged, modify the hosts file under \ system32 \ drivers \ etc of the machine where php is located, and add the name of the machine where the ip address of the machine where SQL server is located.
If the connection is still inaccessible, check whether the machine on which php is located is converted to mdac. Or simply install the SQL Server client.
For php connection to sql2005, I found a lot of information on the network in my csdn blog. at, I finally got it done.
Php connection to sql2005 is now integrated, and FAQ is integrated.

The tutorial I wrote earlier:

Configure the system before connection:
1. check the php5.2.5 \ ntwdblib. dll file. one of the following is under the default file and cannot be connected and replaced.
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 annotation 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 system32 directory of the system. (Php_mssql.dll is included in the php compressed installation package ).
After completing the preceding steps, restart apache.
Note: in actual use, if php is manually installed under iis through the php compressed file, the machine must be restarted, not just iis.
3. configure sqlserver
A. run SQL Server Configuration Manager: SQL Server Configuration Manager to enable Protocols.
B. allow named pipelines "named pipes" and "TCP/IP"
C. right-click "TCP/IP" and open the Properties tag "ip addresses"
D. enter 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:

The code is as follows:


// Link to the database
$ Conn = mssql_connect ('localhost', 'sa ', '123 ');
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 FAQs:
1 error:
Fatal error: Call to undefined function mssql_connect ()
Solution:
Use MSSQL _ series functions
To use these two methods, you need to set them in php. ini:
(1) to allow DCOM, remove the semicolon ";" before com. allow_dcom = TRUE in php. ini.
(2) to use the MSSQL extension, remove the semicolon ";" in php. ini before extension = php_mssql.dll. (Key)
(3) confirm that extension_dir is the correct path. take the local machine as an example: extension_dir = "c: \ AppServ5.2.6 \ php \ ext ".
(4) If the server still reports an error, the file c: \ AppServ5.2.6 \ php \ ext \ php_mssql.dll cannot be found, but the file exists clearly.
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. my files are c: \ AppServ5.2.6 \ php \ ext \ php_mssql.dll; c: \ AppServ5.2.6 \ php \ ntwdblib. dll)
In addition, remember to restart the server after setting it.
2. mssql_connect () Unable to connect to server
Check whether the SQLServer2005 server is normal. check whether TCP/IP is enabled.
Right-click to view properties at the same time:
Enabled? select yes
After confirming that the server is correct, check whether the ntwdblib. dll file is stored in c: \ windows \ system32.
At the same time, ensure that the version of the ntwdblib. dll file corresponds to that of sqlserver:
The following is the correspondence:
2. if the ntwdblib. dll version is 2000.2.8.0, it corresponds to SqlServer2000 (this is the network query information and speculation, and 2000 is not installed)
2. the ntwdblib. dll version 2000.80.194.0 corresponds to SqlServer2005 (this is an experiment that can be used. I installed 2005 in my notebook)
3. the ntwdblib. dll version 2000.80.2039 corresponds to SqlServer2008 (this is a guess that 2008 is not installed)
6. other problems:
If php apache SQL Server2000 is on the same machine, the access is basically normal.
If the SQL Server and php machines are separated, make sure that the machine name on which the SQL Server server is located can be pinged, modify the hosts file under \ system32 \ drivers \ etc of the machine where php is located, and add the name of the machine where the ip address of the machine where SQL server is located.
If the connection is still inaccessible, check whether the machine on which php is located is converted to mdac. Or simply install the SQL Server client.
The solution is as follows:
1. download two files: php_mssql.dll and ntwdblib. dll.
Php_mssql.dll is easy to appear if it is not copied to c: \ windows \ system32.
Pay attention to the version of the ntwdblib2093.dll file, otherwise it will be very depressing.
If your MSSQL database is 2000, the operations are basically the same.
Add a server in the 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 and php5.3.2. It is understood that php5.3 uses Microsoft's FastCGI mode, compared with the traditional CGI mode, this mode adopts a more reasonable startup mode for parsing processes, which is twice faster than CGI. The ISAPI mode is not supported in PHP5.3 or later versions.

After iis6 and ms SQL server 2005 have been installed, the entire installation process is
1. install FastCGI;
2. install php5.3.2;
3. install the SQL Server Driver for PHP 1.1 Driver;

Steps-Apache 2.2.6-PHP 5.2.5-SQL Server 2005-Windows XP SP2: 1. first, configure PHP5 to connect to ms SQL Server 2. download the correct version of ntwdblib. dll (200...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.