


How to connect to MSSQLServer with PHP under Linux_PHP Tutorial
Ask a question I did a very strange project a few days ago. Our company developed a set of SP-side short message service software based on China Unicom's SGIP protocol to provide China Unicom 130 SMS service. This system is under Windows 2000. The database uses Microsoft SQLServer2000 and has been running normally for some time. Recently, in order to provide some information of short message users on the WEB, it is necessary to read and write the SQL Server database from the WEB. Originally, the best partner of the SQL Server database should be Microsoft IIS ASP server script, but our company has always believed that IIS+ASP The stability and security are not satisfactory. I hope to use PHP scripts to read and write SQL Server under Linux. Analyzing the Problem Originally, there is no problem with PHP scripts reading and writing SQL Server. It can work very well under Apache for windows and Windows IIS. Generally, it can be connected through ODBC or SQL Server Client, which are all ready-made under Windows. However, there are no ready-made ODBC and SQLServer Client under Linux and we need to install them ourselves. Solve the problem 1. Related software freetds Source: ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/freetds-0.53.tgz This software can connect MS SQLServer and Sybase databases using Linux and Unix. 2. Installation and configuration steps Step 1: Compile and install freetds: After getting freetds-0.53.tgz, cp freetds-0.53.tgz /tmp/. (Copy the freetds package to the /tmp directory) cd /tmp (enter the directory) tar zxvf freetds- 0.53.tgz (decompressed) cd freetds-0.53 (enter the decompressed directory) ./configure –prefix=/usr/local/freetds --with-tdsver=7.0 gmake (generate Makefile, I have tested it, make can also do it) gmake install (Installation) Regarding the configure above, I would like to say that --prefix=/usr/local/freetds refers to installing into the directory /usr/local/freetds, and --with-tdsver=7.0 refers to installing tds 7.0 version (the latest The problem is that I did not add this compilation parameter, and the result was compiled to 5.0 by default. The port for 5.0 to connect to the database is 4000, not 1433 of SQL Server) Step 2: Recompile PHP4./configure [--with-apxs --with-mysql ...] --with-sybase=/usr/local/freetds (please note it is sybase) make make install Step 3: Configure freetds vi /usr/local/freetds/etc/freetds.conf See the specific configuration in this file Example of description: (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 two methods of Windows domain login or SQLServer account login. Fourth Step: Configure the php.ini file and find; extension=mssql70.so. Remove the comment; to extension=mssql70.so. Step 5: Establish 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, then Note: Carefully read the above installation and configuration process to see which step you are wrong. Note: The sqlserver name is the host parameter defined in /usr/local/freetds/etc/freetds.conf. If you write the IP address, it is the IP address. For other database operations, refer to related mssql functions. Note that Chinese is not supported in sql statements!!! Step 6: Debugging. If you cannot connect, please find it in the freetds configuration file; comment the line dump file = /tmp/freetds.log. Remove the semicolon in front, execute the test script again, and check the /tmp/freetds.log file. It can tell you a lot of error information to help you troubleshoot the problem.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.
