PHP Connection SQL Server 2005 environment configuration and problem solving, sqlserver_php tutorial

Source: Internet
Author: User

PHP Connection SQL Server 2005 environment configuration and problem solving, SQL Servers


One, under Windows PHP Connection SQL Server 2005

Settings: Installed Windows operating system (WIN7 or XP are available, other systems are not tested), under the C drive, PHP 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 one, can not connect and 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 the Php_mssql.dll to php.in extension_dir the specified directory or system system32 directory, located in/php/ext.

You will need to restart Apache after the above steps have been completed.

Note: In practice, it is found that the machine must be restarted, not just IIS, if it is manually installed through PHP compressed files to IIS.

3. Configure SQL Server

A. Running SQL Server Configuration Manager: SQL Server Config Manager, opening protocol protocols

B. Allow Named pipes "Named Pipes" and "TCP/IP"

C. Right-click on "TCP/IP" to open the Properties property tag "IP Address"

D. In TCP dynamic port "TCP Ports" fill in 1433, pay attention to assigning the correct IP address.

E. Restarting SQL Server

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

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 functions

To use both of these, you need to set the php.ini:

(1) Allow DCOM, need to be in php.ini; Com.allow_dcom=true before the semicolon ";" Remove.

(2) The use of MSSQL extension, need php.ini; Extension=php_mssql.dll before the semicolon ";" Remove. Key

(3) Confirm that Extension_dir is the correct path, take this machine as an example: Extension_dir = "C:\php\ext".

(4) If the machine error is still not found C:\php\ext\php_mssql.dll but clearly exists this file.

Workaround: Copy the 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:\php\ext\php_mssql.dll;c:\php\ntwdblib.dll)

Also, remember to restart the server after you set it up well.

has enabled whether to select Yes

After confirming that the server is correct, confirm that the Ntwdblib.dll file location is placed under C:\Windows\System32

Also make sure that the version of Ntwdblib.dll 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 Web check data and guessing, not loaded 2000)

2.ntwdblib.dll version for 2000.80.194.0 is the corresponding SqlServer2005 (this is the experimental proof can be used, I was a notebook loaded 2005)

3.ntwdblib.dll version for 2000.80.2039 is correspondence SqlServer2008 (this is guessing not loaded 2008)

6. Other issues:

If PHP Apache SQL Server2005 are on the same machine, access is basically no problem.

If SQL Server2005 and PHP machines are separate, you need to verify that the machine name of the machine where the ping SQL Server is located can pass, if it does not pass, modify the Hosts file under the \System32\Drivers\Etc of the machine where PHP is located, add a line Machine name of machine IP SQL Server where SQL Server is located.

If you are still unable to access it, you need to verify that the machine on which PHP is located has installation MDAC. or simply install SQL Server client as well.

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:\Windows\System32, it will be easy to appear

Ntwdblib2093.dll this file to pay attention to the version, or behind the very depressed.

Second, Linux under the PHP connection SQL Server 2005

1, first install the lamp environment in accordance with the needs of other than PHP components. 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 NOTE: This step needs to be noted--with-tdsver

2, Configuration FreeTDS

server2005 corresponding TDS version is 7.2 (seemingly can be found on the Internet write 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 parameter 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 items that compile 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 loading FreeTDS, the following actions are required (official FAQ):

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

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

4, after the installation of PHP, all the preparation work is completed, the following can be restarted Apache, you can use PHP to call SQL Server 2005.


PHP Connection sqlserver2005 Not connected

What are you suggesting?
If you use PHP to link SQL Server under Windows, the following issues occur according to the correct general configuration

PHP has removed php.ini, and Apache still cannot load php_mssql.dll after comments in front of Extension=php_mssql.dll.

Use the Mssql_connect () function in PHP the Times below error

Call to undefined function mssql_connect ()

The contents of the error log are PHP startup:unable to load Dynamic library ' D:\\webservice\\php-5.2.8-win32\\ext\\php_mssql.dll '

Finding the information on the Internet found that this problem is actually a NTwdblib.dll, and this dynamic connection library file is a SQL Server Client connection library, if the native installation of SQL SERVER2000/2005 client will not occur this problem. Locate a NTwdblib.dll file and place it in the System32 folder to resolve the problem.

PHP connection problems with remote SQL Server 2005, resolved under

Ntwdblib.dll file

1.Copy to the PHP installation directory and C:\Windows\System32 directory, stop IIS or Apache.
2. Cover Apache2.2.6\bin Ntwdblib.dll
3. Cover php5.2.5 Ntwdblib.dll

Assume:
SQL Server2005 is a B machine
The machine that needs to be connected is a machine.
Ntwdblib.dll is a file generated after the installation of a remote SQL Server, you need to copy this file to the above directory overlay on the A machine,

4. Modify the PHP configuration file in the php.ini file to change mssql.secure_connection = ON, for the link LAN Server This configuration is not correct, should be mssql.secure_connection = Off

http://www.bkjia.com/PHPjc/861796.html www.bkjia.com true http://www.bkjia.com/PHPjc/861796.html techarticle PHP Connection SQL Server 2005 environment configuration and Problem resolution, SQL Server one, Windows PHP connection SQL Server 2005 settings: Installed Windows operating system (WIN7 or XP can be, other systems are not measured ...)

  • 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.