One, Windows PHP connection SQL Server 2005
Setup: Installed Windows operating system (Win7 or XP, other systems are not tested), under C disk, PHP's related files are located under C:/php, the configuration file php.ini is located under C:\Windows.
Configure the system before connecting:
1, check the file Php\ntwdblib.dll, the default PHP installation directory below A, can not be connected to replace.
Download the correct version of Ntwdblib.dll (2000.80.194.0)
2. Configure PHP
A, open php.in to remove the extension=php_mssql.dll annotation symbol.
B, open php.in to change mssql.secure_connection = off to ON.
C, copy Php_mssql.dll to php.in extension_dir specified directory or system system32 directory, located in/php/ext.
You will need to restart Apache after completing these steps.
Note: In practice, if you manually install PHP to IIS by using PHP compressed files, you must restart the machine instead of just IIS.
3. Configure SQL Server
A. Run SQL Server Configuration Manager: SQL Server Configuration Manager, open protocol protocols
B. Allow Named pipes "Named Pipes" and "TCP/IP"
C. Right-click on "TCP/IP" to open the Property Properties tab "Address"
D. In the TCP dynamic port, "Ports", fill in 1433, and pay attention to assigning the correct IP address.
E. Restart SQL Server
4. Connect MS SQL Server 2005 using the following methods:
The code is as follows, save as test.php:
< PHP
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 results
$Num =mssql_num_rows ($AdminResult);
for ($i =0; $i
Input http://127.0.0.1/test.php
To access:
5.FAQ FAQ:
1 Error:
Fatal error:call to undefined function mssql_connect ()
Solve:
Using the Mssql_ series function
To use both of these needs to be set in php.ini:
(1) Allow DCOM, need to be php.ini in the com.allow_dcom=true before the semicolon ";" Remove.
(2) The use of MSSQL extension, need to php.ini in the Extension=php_mssql.dll before the semicolon ";" Remove. Key
(3) Confirm that the Extension_dir is the correct path and take this machine as an example: Extension_dir = "C:\php\ext".
(4) If the machine still complains that it cannot find c:\php\ext\php_mssql.dll but there is clearly this file.
Workaround: Php_mssql.dll,ntwdblib.dll Copy to the system directory \system32 restart the test.
(Note: The above two DLL files are not in the same directory, my C:\php\ext\php_mssql.dll;c:\php\ntwdblib.dll)
In addition, remember to restart the server after setting.
Enabled whether the selection is
After confirming that the server is correct, confirm that the Ntwdblib.dll file location is placed under C:\Windows\System32
Also ensure that the Ntwdblib.dll version of this file corresponds to the version of SQL Server:
The following are the corresponding relationships:
1.ntwdblib.dll version for 2000.2.8.0 is the corresponding SqlServer2000 (this is the network search information and speculation, not installed 2000)
2.ntwdblib.dll version for 2000.80.194.0 is the corresponding SqlServer2005 (this is to use the experimental proof, I was using a notebook installed 2005)
The 3.ntwdblib.dll version for 2000.80.2039 is corresponding to the SqlServer2008 (this is guessing not to be loaded 2008)
6. Other issues:
If PHP Apache SQL Server2005 are all on the same machine, access is basically fine.
If the SQL Server2005 and PHP machine are separate, you need to confirm ping SQL Server machine name of the machine can pass, if not, modify the PHP machine \System32\Drivers\Etc under the Hosts file, add a line The machine name of the machine where SQL Server is located on the machine IP SQL Server.
If you still cannot access it, you need to verify that the machine on which PHP is located has Damin MDAC. or simply install the SQL Server client. OK.
Solve the problem as follows:
1. Download two files Php_mssql.dll and Ntwdblib.dll
Php_mssql.dll If this doesn't replicate to C:\Windows\System32, it's easy to show up.
Ntwdblib2093.dll this file to pay attention to the version, or behind the very depressed.
Two, Linux under the PHP connection SQL Server 2005
1. Install lamp environment In addition to other components except PHP as needed first. Use FreeTDS to connect Ms SQL installation in Linux FreeTDS
./configure--prefix=/usr/local/freetds--with-tdsver=8.0--enable-msdblib--enable-dbmfix--with-gnu-ld- Enable-shared--enable-static
Make
Make install
Important tip One: This step needs to be noted is--with-tdsver
2. Configure FreeTDS
The server2005 corresponding TDS version is 7.2 (it looks like the internet can be found on the 8.0)
Configure/usr/local/freetds/etc/freetds.conf
# A Typical Microsoft server
[1.1.1.21]
Host = 1.1.1.21
Port = 1433
TDS Version = 7.0
Important: When calling the Mssql_connect function, it should be noted that the first argument should be [1.1.1.21] (that is, the configuration in freetds.conf), not the ip! of SQL Server
3. Compile and install PHP
The configuration entries for compiling PHP are set as needed, but the configuration items that must be added are:--with-mssql=/usr/local/freetds/
Note: If the FreeTDS directory cannot be found when compiling PHP load FreeTDS, the following actions are required (official FAQ):
Touch/usr/local/freetds/include/tds.h
Touch/usr/local/freetds/lib/libtds.a
4, after installing PHP, all the preparation work is completed, the following can restart Apache, you can use PHP to invoke SQL Server 2005.