PHP _php Tutorial for connecting MS SQL Server under Linux

Source: Internet
Author: User
Tags sybase microsoft iis
Ask questions

A few days ago did a very strange project, my company developed a set of China Unicom SGIP Protocol, SP-terminal short Message service software, providing unicom 130 SMS service. The system is under Windows 2000, the database is Microsoft SQLServer2000, and it has been running for a while. and recently because to provide some information on the web for short message users, you need to read and write SQL Server database from the Web, the SQL Server database is the best partner should be Microsoft IIS ASP Server script, but my company always think iis+ The stability and security of ASP is not satisfactory, hoping to read and write SQL Server with PHP script under Linux.


Analyze Problems

PHP scripts Read and write SQL Server is not a problem, in Apache for Windows and Windows IIS can work very well, generally can be connected via ODBC or SQL Server client, which is available under Windows. But there is no existing ODBC and SQL Server Client under Linux, and we need to install it ourselves.

solve the problem

first, related software
FreeTDS Source: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/freetds-0.53.tgz
This software can connect MS SQL Server and Sybase databases with Linux and UNIX.

Second, installation configuration steps

First step: Compile and install FreeTDS:
After getting freetds-0.53.tgz
CP freetds-0.53.tgz/tmp/. (Copy FreeTDS package to/tmp directory)
Cd/tmp (Enter directory)
Tar zxvf freetds-0.53.tgz (unzip)
CD freetds-0.53 (enter the extracted directory)
./configure–prefix=/usr/local/freetds--with-tdsver=7.0
Gmake (Generate makefile, I've tried, make can also)
Gmake Install (Installation)
About the above configure I would like to say,--prefix=/usr/local/freetds refers to the installation of/usr/local/freetds this directory,--with-tdsver=7.0 refers to the installation of TDS Version 7.0 (most open I did not add this compilation parameter, the result is compiled by default to 5.0.) 5.0 the port to connect to the database is 4000, not SQL Server 1433)

Step Two: Recompile PHP4
./configure [--with-apxs--with-mysql ...]--with-sybase=/usr/local/freetds (please note that Sybase)
Make
Make install
Step Three: Configure FreeTDS
Vi/usr/local/freetds/etc/freetds.conf
See instructions in this file for specific configuration
Example: (Typical configuration)
[SQL Server]
Host = SQL_SERVER_NAME_OR_HOST_IP (your SQL Server machine name or IP address)
Port = 1433
TDS Version = 7.0
In this configuration file can be configured Windows domain login or SQL Server account login two ways

Fourth step: Configure the php.ini file
to find; extension=mssql70.so.
Take notes;
Extension=mssql70.so

Fifth step: Establishing a database connection in PHP
$link =mssql_connect ("SQL Server", $your _username, $your _password) or Die ("can ' t connect to Database");
Echo $link;
Run the above script in the browser, if you get a link number then congratulations, you've already configured, if it appears call to undefined function:mssql_connect () That means look closely at the installation configuration process to see which step you are not right.
Note: The SQL Server name is the host parameter defined in/usr/local/freetds/etc/freetds.conf, if you write an IP address, it is the IP address.
Other database operations reference related MSSQL functions
Note that the Chinese!!! is not supported in SQL statements

Sixth step: Commissioning
If you cannot connect, locate it in the FreeTDS configuration file, dump file =/tmp/freetds.log, comment out the previous semicolon, and then execute the test script to see/tmp/ Freetds.log file, it can tell you a lot of error information to help you troubleshoot problems.



http://www.bkjia.com/PHPjc/446881.html www.bkjia.com true http://www.bkjia.com/PHPjc/446881.html techarticle ask questions a few days ago to do a very strange project, I developed a set of China Unicom SGIP Protocol, SP-terminal short Message service software, provide unicom 130 SMS service. This set of systems ...

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