Linux下安装PHP MSSQL扩展教程_PHP
PHP天然就对MySQL有良好的支持,但是想要用PHP对SQL Server进行操作,则需要花点时间了。今天刚好团队里的一个项目需要用PHP对SQL Server进行操作,遂帮忙配置好环境。
首先说明下,服务器的系统版本为SUSE Linux Enterprise Server 10 SP3。
1. 安装FreeTDS
地址:FreeTDS
代码如下:
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz
cd freetds-0.82
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix
make && make install
成功安装完,最好更新下动态连接库缓存:
代码如下:
echo "/usr/local/freetds/lib" >> /etc/ld.so.conf
ldconfig
2. 配置FreeTDS及连接测试
FreeTDS的配置文件放在安装目录的etc里,根据第一步的configure参数,我们FreeTDS安装在/usr/local/freetds:
代码如下:
vim /usr/local/freetds/etc/freetds.conf
由于不太清楚FreeTDS的具体有哪些可配置项,这里就不深入了,但是提供个比较重要的配置,用来解决中文乱码的问题。在配置文件添加如下语句:
代码如下:
client charset = utf8
然后,我们使用tsql命令测试下是否能正常连接上SQL Server数据库:
代码如下:
cd /usr/local/freetds/bin
./tsql -H 192.168.0.254 -p 1433 -U sa -P 123456
正常连接的话应该显示如下语句:
代码如下:
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
1>
3. 安装php的mssql扩展
服务器上的php版本为5.3.13,php已安装在/usr/local/services/php下,扩展的目录为/usr/local/services/php/extensions。下面是安装mssql扩展的方法:
代码如下:
cd php-5.3.13/ext/mssql/
/usr/local/services/php/bin/phpize
./configure --with-php-config=/usr/local/services/php/bin/php-config --with-mssql=/usr/local/freetds
make #生成扩展文件,放在当前目录的module文件夹下
cp modules/mssql.so /usr/local/services/php/extensions/ #把扩展文件复制到PHP的扩展目录下
4. 配置php.ini并验证安装结果
打开php.ini,添加如下扩展语句:
代码如下:
extension=mssql.so
重启PHP服务后(服务器用的是php-fpm),打印phpinfo,出现如下配置则代表php能正常操作SQL Server了。

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

AI Hentai Generator
Generate AI Hentai for free.

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



JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

C language conditional compilation is a mechanism for selectively compiling code blocks based on compile-time conditions. The introductory methods include: using #if and #else directives to select code blocks based on conditions. Commonly used conditional expressions include STDC, _WIN32 and linux. Practical case: Print different messages according to the operating system. Use different data types according to the number of digits of the system. Different header files are supported according to the compiler. Conditional compilation enhances the portability and flexibility of the code, making it adaptable to compiler, operating system, and CPU architecture changes.
