Linux Install the PHP MSSQL expansion tutorial _php Tips

Source: Internet
Author: User
Tags locale mssql

PHP naturally has good support for MySQL, but it takes a while to work with SQL Server in PHP. Today, just one project in the team needed to operate SQL Server in PHP, so it helped to configure the environment.

First, the system version of the server is SuSE Linux Enterprise server SP3.

1. Install FreeTDS

Address: FreeTDS

Copy Code code as follows:

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

After successful installation, it is best to update the Dynamic Connection Library cache:
Copy Code code as follows:

echo "/usr/local/freetds/lib" >>/etc/ld.so.conf
Ldconfig

2. Configure FreeTDS and connectivity testing

FreeTDS's configuration file is placed in the installation directory, etc, according to the first step of the Configure parameters, we FreeTDS installed in/usr/local/freetds:

Copy Code code as follows:

Vim/usr/local/freetds/etc/freetds.conf

Because it is not clear what FreeTDS specific configurable items, here is not in-depth, but provide a more important configuration, to solve the problem of Chinese garbled. Add the following statement to the configuration file:

Copy Code code as follows:

Client CharSet = UTF8

Then, we use the TSQL command to test whether the SQL Server database is properly connected:

Copy Code code as follows:

Cd/usr/local/freetds/bin
./tsql-h 192.168.0.254-p 1433-u sa-p 123456

A normal connection should display the following statement:

Copy Code code as follows:

Locale is "ZH_CN. UTF-8 "
Locale CharSet is "UTF-8"
1>

3. Install the MSSQL extension of PHP

The PHP version on the server is 5.3.13,php installed under/usr/local/services/php and the extended directory is/usr/local/services/php/extensions. Here's how to install the MSSQL extension:

Copy Code code as follows:

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 #生成扩展文件, placed under the module folder of the current directory
CP modules/mssql.so/usr/local/services/php/extensions/#把扩展文件复制到PHP的扩展目录下

4. Configure php.ini and verify installation results

Open PHP.ini and add the following extension statement:

Copy Code code as follows:

Extension=mssql.so

After restarting the PHP service (the server is using PHP-FPM), printing the phpinfo, the following configuration will represent PHP's normal operation of SQL Server.

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.