search
HomeBackend DevelopmentPHP TutorialHow 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531761.htmlTechArticleI did a very strange project a few days ago. Our company developed a set of SGIP protocols based on China Unicom The SP-side short message service software provides China Unicom 130 SMS service. This system...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use