How to connect PHP to MSSQLServer in Linux _ PHP Tutorial

Source: Internet
Author: User
Tags microsoft iis
How to connect PHP to MSSQLServer in Linux. A very strange project was made a few days before the problem was raised. our company developed a set of SP-side short message service software based on the SGIP Protocol of China Unicom to provide Unicom's 130 short message service. This system made a very strange project a few days ago. our company developed a set of SP-side short message service software based on the SGIP Protocol of China Unicom to provide Unicom 130 short message service. This system is in Windows 2000, and the database uses Microsoft SQLServer2000, and has been running normally for a while. Recently, to provide short message user information on the WEB, you need to read and write SQL Server databases from the WEB. the best partner of SQL Server databases should be Microsoft IIS ASP server scripts, however, my company has always believed that the stability and security of IIS + ASP are not satisfactory, and I hope to use PHP scripts to read and write SQLServer in Linux. Analysis of the problem is that PHP scripts can read and write SQL Server. it works well in Apache for windows and Windows IIS. generally, it can be connected through ODBC or SQL Server Client, these are all ready-made in Windows. However, ODBC and SQLServer Client are not available in Linux. we need to install them on our own. Solution 1. source of related software freetds: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/freetds-0.53.tgz This software can use Linux and Unix to connect MS SQLServer and Sybase databases. II. installation configuration Step 1: compile and install freetds: Get the freetds-0.53.tgz cp freetds-0.53.tgz/tmp /. (Copy freetds package to the/tmp directory) cd/tmp (enter the directory) tar zxvf freetds-0.53.tgz (unzip) cd freetds-0.53 (enter the directory after decompression ). /configure-prefix =/usr/local/freetds -- with-tdsver = 7.0 gmake (generate Makefile, I tried it, make can also be) gmake install (installation) for more information about configure, -- prefix =/usr/local/freetds indicates that it is installed in the/usr/local/freetds directory, -- with-tdsver = 7.0 refers to the installation of the tds 7.0 version (the most open is that I did not add this compilation parameter, and the result is compiled according to the default Translated into 5.0. 5.0 the port connecting to the database is 4000, not 1433 of SQLServer) Step 2: recompile PHP4. /configure [-- with-apxs -- with-mysql...] -- with-sybase =/usr/local/freetds (sybase) make install Step 3: Configure freetds vi/usr/local/freetds/etc/freetds. for specific configuration of conf, see the instructions in this file: (typical configuration) [sqlserver] host = SQL _server_name_or_host_ip (your SQLServer machine name or IP address) port = 1433 tds version = 7.0 in this configuration file, you can configure Windows domain login or SQLServer account login. Step 4: Configure php. ini file found; extension = Remove the comment from mssql70.so to extension = mssql70.so Step 5: create a database connection in php $ link = mssql_connect ("sqlserver", $ 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, congratulations, you have configured it, if Call to undefined function: mssql_connect () appears, it indicates that you have not followed the installation and configuration process. Note: The sqlserver name is the host parameter defined in/usr/local/freetds/etc/freetds. conf. if you write an IP address, it is the IP address. For other database operations, see mssql functions. Chinese characters are not supported in SQL statements !!! Step 6: If the connection fails, find it in the freetds configuration file; dump file =/tmp/freetds. log line, comment out the semicolon, and then execute the test script to check/tmp/freetds. log file, which can tell you a lot of error information to help you solve the problem.

Vivo made a very strange project a few days ago. our company developed a set of SP-side short message service software based on the SGIP Protocol of China Unicom to provide Unicom's 130 short message service. This system...

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.