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:
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:
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.