Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to connect to SQLServer2005 database in PHP

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to connect to the SQLServer2005 database in PHP, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

1. Check that the file php5.2.5\ ntwdblib.dll has one below by default and cannot be connected and replaced.

two。 Configure php

A. Open php.in to remove the annotation symbols from extension=php_mssql.dll.

B. Open php.in and change mssql.secure_connection = Off to on.

C. Copy the php_mssql.dll to the directory specified by extension_dir in php.in or to the system system32 directory. Php_mssql.dll is available in the compressed installation package of php.

You need to restart apache after the above steps are completed.

Note: in practice, it is found that if you manually install php to iis through a php zip file, you must restart the machine instead of just iis.

3. Configure sqlserver

a. Run SQL Server configuration Manager: SQL Server Configuration Manager, and open the protocol Protocols

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

c. Right-click "tcp/ip" to open the attribute Properties tab "IP addresses"

d. Enter 1433 in the TCP dynamic port "TCP Dynamic Ports"

e. Restart SQL Server

-

4. Connect to MS SQL Server 2005 in the following ways:

The code is as follows:

/ / Link the 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 the result

$Num=mssql_num_rows ($AdminResult)

For ($iSuppli

Enter http://127.0.0.1

5.FAQ FAQ:

1 error:

Fatal error: Call to undefined function mssql_connect ()

Resolve:

Use MSSQL_ series functions

To use both of these, 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 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 machine still reports an error that c:\ AppServ5.2.6\ php\ ext\ php_mssql.dll can not be found, but this file clearly exists.

Solution: copy php_mssql.dll,ntwdblib.dll to the system directory\ system32 to restart the test.

(note: the above two dll files are not in the same directory, mine is c:\ AppServ5.2.6\ php\ ext\ php_mssql.dll;c:\ AppServ5.2.6\ php\ ntwdblib.dll)

In addition, remember to restart the server when it is set up.

2.mssql_connect () Unable to connect to server

Confirm that the SQLServer2005 server is normal. Check that TCP/IP is enabled

At the same time, right-click to view properties:

Has been enabled whether to select Yes

After verifying that the server is correct, verify that the location of the ntwdblib.dll file is placed under c:\ windows\ system32

At the same time, make sure that the version of the ntwdblib.dll file corresponds to the version of sqlserver:

Here is the corresponding relationship:

2.ntwdblib.dll version 2000.2.8.0 corresponds to SqlServer2000 (this is a network search and guess, not installed 2000)

2.ntwdblib.dll version 2000.80.194.0 is corresponding to SqlServer2005 (this is proved by experiments, I installed 2005 in my laptop)

3.ntwdblib.dll version 2000.80.2039 corresponds to SqlServer2008 (this is guessed that 2008 is not installed)

6. Other questions:

If the php apache Sql Server2000 are all on the same machine, there is almost no problem with access.

If the Sql Server2000 and php machines are separate, you need to make sure that the machine name of the ping sqlserver machine is workable. If not, modify the hosts file under\ system32\ drivers\ etc of the machine where the php belongs, and add the name of the machine where the sqlserver belongs to the machine ip sqlserver.

If it is still unreachable, you need to make sure that the machine where php is located has been darkly converted to mdac. Why not just install the client of sqlserver.

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:\ windows\ system32, it is easy to appear.

Pay attention to the version of the ntwdblib2093.dll file, or it will be very depressing.

This is the answer to the question about how to connect to the SQLServer2005 database in PHP. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report