Pdo_dblib extension of ThinkPHP5 link MSSQL database in Linux system

Source: Internet
Author: User
Tags dsn mssql zts

LinUX (centOS6.8) system ThinkPHP5 link pdo_dblib extension of MSSQL Database
The first step is to download and install freetds-current.tar.gz as follows
Ftp://ftp.freetds.org/pub/freetds/current/freetds-current.tar.gz
1.1 Download unzip and enter the folder (in fact you can also unzip and then upload to the Linux server)

wget ftp://ftp.freetds.org/pub/freetds/current/freetds-current.tar.gztar zxvf freetds-  Current. Tar. gzcd FreeTDS-stable

* Unzip the path after you see this is not necessarily right
1.2 Execution./configure

./configure--prefix=/usr/local/freetds--with-tdsver=7.1--enable-msdblib

1.3 Execute make Install

Make && make install

The second step installs the PHP installation pdo_dblib extension
2.1 into your installed PHP source files directory, if you can not find the same version of the PHP files to unzip later upload to the Linux server I take this path/root/scr/php/ext/pdo_dblib example

CD  /root/scr/php/ext/pdo_dblib

2.2 Execute Phpize If your PHP is not installed under the/usr/local path you want to modify the PHP path for yourself

/usr/local/php/bin/phpize

For example, my PHP installation path for/www/wdlinux/apache_php-5.6.21/will be executed/www/wdlinux/apache_php-5.6.21/bin/phpize

2.3 implementation./configure Ibid. If your PHP is not installed under the/usr/local path you want to modify the PHP path for yourself

./configure--with-php-config=/usr/local/php/bin/php-config--with-pdo-dblib=/usr/local/freetds

For example, my PHP installation path is/www/wdlinux/apache_php-5.6.21/so./configure--with-php-config=/www/wdlinux/apache_php-5.6.21/bin/ Php-config--with-pdo-dblib=/usr/local/freetds

2.4 Execute make Install

Make && make install

Step three modify PHP.ini ibid. If your PHP is not installed under the/usr/local path you want to modify the PHP path for yourself
For example, my PHP installation path is/www/wdlinux/apache_php-5.6.21/
3.1 Verifying the path to the compiled file
Enter/usr/local/php/lib/php/extensions inside to see inside or subordinate directory there is no mssql.so and pdo_dblib.so file
If so, then the compilation was successful.
3.2 Modifying PHP.ini

Vi/usr/local/php/etc/php.ini

and add the following code at the bottom and save VI changes (first press I into the edit mode, added after the successful press ESC to launch the edit mode and then revenue: Wq after press ENTER to save)

// extension= "/usr/local/php/lib/php/extensions/mssql.so" extension= "/usr/local/php/lib/php/extensions/ Pdo_dblib.so "

Different servers may have different code, and my PHP installation and compilation paths will vary

// extension= "/www/wdlinux/apache_php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/mssql.so" extension= "/www/wdlinux/apache_php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/pdo_dblib.so"

3.3 After all, restart Apache Apache you can also enter reboot to restart the server

Service httpd Restart

3.4 If you feel uncomfortable check the PHP probe file to see if MSSQL and Pdo_dblib are installed successfully


Step fourth Download the attachment and copy the database driver extension file to the thinkphp file
The file is placed under the main program below/THINKPHP/LIBRARY/THINK/DB
There are two files in the Builder and connector folders. Two questions the same name is dblib.php but you can't confuse it.
Fifth Step configuration database.php file

return [    //Database Type' Type ' = ' dblib ',//Server Address' Hostname ' = ' 192.168.1.210 ',//Database name' Database ' = ' mikkle_weixin ',//User name' Username ' = ' sa ',//Password' Password ' = ' 123123123123123 ',//Port' Hostport ' = ' 1433 ',//Connection DSN' DSN ' = ',//Database Connection Parameters' Params ' = [],//database encoding is UTF8 by default' CharSet ' = ' utf8 ',//database table Prefixes' Prefix ' = ' weixin_ ',//Database Debug Mode' Debug ' =true,//Database Deployment method: 0 Centralized (single server), 1 distributed (Master-slave server)' Deploy ' = 0,//whether the database reads and writes separate master-slave valid' Rw_separate ' =false,//number of master servers for read-write separation' Master_num ' = 1,//Specify the number from the server' Slave_no ' = ',//whether the field is strictly checked for existence' Fields_strict ' =true,//Data set return type array Arrays Collection collection Objects' Resultset_type ' = ' array ',//whether to write timestamp fields automatically' Auto_timestamp ' =true,//Whether SQL performance analysis is required' Sql_explain ' =false,];

Download extensions

Pdo_dblib extension of ThinkPHP5 link MSSQL database in Linux system

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.