Linux under PHP to connect MS SQL Server approach

Source: Internet
Author: User
Tags ftp odbc mssql php script sybase microsoft iis
Ask a question a few days ago did a very strange project, my company developed a set of China Unicom SGIP Protocol of the SP terminal Short Message Service software, to provide unicom 130 SMS services. This system is under Windows 2000, the database is using Microsoft SQLServer2000, and has been running for some time. Recently, because to provide some information on the web for short message users, you need to read and write the SQL Server database from the Web, the best partner for SQL Server database should be Microsoft IIS ASP Server script, but our company always think iis+ ASP's stability and security are not satisfactory, I hope to be able to read and write SQL Server with PHP script under Linux.
Analyzing the problem originally PHP script read-write SQL Server is no problem, it works well under Apache for Windows and Windows IIS, and can generally be connected through ODBC or SQL Server client. This is all available under Windows. But there are no out-of-the-box ODBC and SQL Server Client under Linux, and we need to install them ourselves.
Solve the problem one, related software FreeTDS Source: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/freetds-0.53.tgz This software can use Linux and UNIX to connect MS SQL Server and Sybase databases.
 Second, the installation configuration steps the first step: compiles installs the FreeTDS: obtains freetds-0.53.tgz after the CP freetds-0.53.tgz/tmp/. (Copy FreeTDS package to/tmp directory) cd/tmp (enter directory) tar zxvf freetds-0.53.tgz (extract) CD freetds-0.53 (into the unpacked directory)./configure–prefix=/usr/local /freetds--with-tdsver=7.0 gmake (Generate makefile, I have experimented, make can also) gmake install (installation) about the top configure I want to say,--prefix=/usr/local/ FreeTDS refers to the installation to/usr/local/freetds this directory,--with-tdsver=7.0 refers to the installation of TDs 7.0 version (the most open is I did not add this compilation parameter, the result is compiled to 5.0 by default). 5.0 the port that connects the database is 4000, not SQL Server 1433) Step two: Recompile PHP4./configure [--with-apxs--with-mysql ...]--with-sybase=/usr/local/ FreeTDS (note is Sybase) make make install step three: Configure FreeTDS vi/usr/local/freetds/etc/freetds.conf specific configuration See the example in the file: (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, you can configure Windows domain login or SQL Server account login Two ways fourth: Configure the php.ini file to find; extension=mssql70.so the annotation to extension=mssql70.so Fifth step: Establish 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 an LInk so congratulations, you have been configured, if there is a call to undefined function:mssql_connect () that the instructions carefully look at the installation configuration process to see if you are not right.
Note: SQL Server name is the host parameter defined in/usr/local/freetds/etc/freetds.conf, if you write an IP address that is an IP address.
Other database operations reference related MSSQL functions note that Chinese is not supported in SQL statements!!! Sixth step: Debug if there is no connection, please find in the FreeTDS configuration file, dump file =/tmp/freetds.log This line, comment out the preceding semicolon, and then execute the test script, see/tmp/ Freetds.log file, it can tell you a lot of wrong information to help you eliminate the problem.
Related Article

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.