Home >Backend Development >PHP Tutorial >PHP connection to sql server 2005 environment configuration and problem solving, sqlserver_PHP tutorial

PHP connection to sql server 2005 environment configuration and problem solving, sqlserver_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:21:031214browse

PHP connection to sql server 2005 environment configuration and problem solving, sqlserver

1. PHP connection to SQLServer 2005 under Windows

Settings: The installed Windows operating system (Win7 or Under Windows.

Configure the system before connecting:

1. Check the file phpntwdblib.dll. There is one under the default PHP installation directory, which cannot be connected and replaced.

Download the correct version of ntwdblib.dll (2000.80.194.0)

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, located in /PHP/ext.

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 the protocol Protocols

b. Allow named pipes "named pipes" and "tcp/ip"

c. Right-click "tcp/ip" and open the Properties tab "IP Address"

        d. Fill in 1433 in the TCP Dynamic Ports "TCP Dynamic Ports" and pay attention to assigning the correct IP address.

e. Restart SQL Server

4. Connect to MS SQL Server 2005 using the following method:

The code is as follows, save it 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

Enter http://127.0.0.1/test.php

To visit:

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 remove the semicolon ";" before ;com.allow_dcom=TRUE in php.ini.

(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:phpext".

(4) If the machine still reports an error saying that c:phpextphp_mssql.dll cannot be found but this file clearly 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 are c:phpextphp_mssql.dll; c:phpntwdblib.dll)

In addition, remember to restart the server after setting it up.

Already enabled? Select Yes

After confirming that the server is correct, 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:

1.ntwdblib.dll version is 2000.2.8.0, which corresponds to SqlServer2000 (this is based on online information and guesswork, 2000 is not installed)

The version of 2.ntwdblib.dll is 2000.80.194.0, which corresponds to SqlServer2005 (this is proved by experiments that it can be used, I installed 2005 on my laptop)

The version of 3.ntwdblib.dll is 2000.80.2039, which corresponds to SqlServer2008 (this is a guess that 2008 is not installed)

6. Other questions:

If php apache Sql Server2005 is on the same machine, there will be no problem accessing it.

If Sql Server2005 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.

The problem is solved 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 appear

Pay attention to the version of this file ntwdblib2093.dll, otherwise it will be very frustrating later.

2. Connect php to sql server 2005 under Linux

1. First install other components in the LAMP environment except php as needed. Use freetds to connect to MS SQL in Linux and install 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 1: What needs to be paid attention to in this step is--with-tdsver

2. Configure freetds

The tds version corresponding to server2005 is 7.2 (it seems that everything you can find online says 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 note: When calling the mssql_connect function, it should be noted that its first parameter should be [1.1.1.21] (that is, the configuration in freetds.conf), not the IP of the sql server!

3. Compile and install php

The configuration items 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 to load freetds, you need to do the following (official Faq):

touch /usr/local/freetds/include/tds.h

touch /usr/local/freetds/lib/libtds.a

4. After installing php, all preparations are completed. Now you can restart apache and use php to call sql server 2005.

php cannot connect to sqlserver2005

Tip what?
If you use php to connect to SQL Server under Windows, the following problems will occur according to the correct general configuration

PHP removes the comment in front of php.ini; extension=php_mssql.dll and Apache still cannot load php_mssql .dll.

When using the mssql_connect() function in PHP, the following error is reported

Call to undefined function mssql_connect()

The content recorded in the error log is PHP Startup: Unable to load dynamic library 'D:\\WebService\\php-5.2.8-Win32\\ext\\php_mssql.dll'

After searching for information online, I found that this problem is actually missing a NTwdblib.dll, and this The dynamic link library file is the SQL SERVER client connection library. If the client of SQL Server2000/2005 is installed on this machine, this problem will not occur. This problem can be solved by finding an NTwdblib.dll file and placing it in the System32 folder.

The problem of php connecting to remote sql server 2005, please solve it

ntwdblib.dll file

1.Copy to the php installation directory and the c:\windows\system32 directory, and stop IIS or Apache.
2. Overwrite apache2.2.6\bin ntwdblib.dll
3. Overwrite php5.2.5 ntwdblib.dll

Assumption:
sql server2005 is machine B
The machine that needs to be connected is Machine A
ntwdblib.dll is a file generated after the installation of remote sql server. You need to copy this file to the above directory on machine A to overwrite it.

4. Modify the php configuration file in PHP.ini Change mssql.secure_connection = On in the file. This configuration is incorrect for servers connected to the LAN. It should be mssql.secure_connection = Off

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/861796.htmlTechArticlePHP connection to sql server 2005 environment configuration and problem solving, sqlserver 1. PHP connection to SQLServer 2005 under Windows Settings: Installation Windows operating system (Win7 or XP is acceptable, other systems have not been tested yet...
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