How to install the MSSQL module in PHP in Linux

Source: Internet
Author: User

1. install and configure freetds
CopyCode The Code is as follows: wget http://mirrors.xmu.edu.cn/ubuntu/archive/pool/main/f/freetds/freetds_0.82.orig.tar.gz
Tar zxf freetds_0.82.orig.tar.gz
CD freetds_0.82
./Configure -- prefix =/usr/local/freetds -- With-tdsver = 8.0 -- enable-msdblib -- enable-dbmfix -- With-GNU-LD -- enable-shared -- enable-static
Make & make install

2. Compile the php mssql module copy Code the code is as follows: CD/path/to/PHP/source enter the PHP source code directory
Cd EXT/MSSQL enter the MSSQL Module source code directory
/usr/local/webserver/PHP/bin/phpize generate the compilation configuration file
. /configure-with-PHP-Config =/usr/local/webserver/PHP/bin/PHP-config-with-MSSQL =/usr/local/freetds
make
make install
build MSSQL after compilation. so, modify PHP. INI:
extension = "/path/to/extension/MSSQL. so "

3. Configure MSSQL
copy Code the code is as follows: CD/usr/local/freetds/etc
edit file:
VI freetds. conf
[Global]
# TDS protocol version
; TDS version = 4.2
# whether to write a tdsdump file for diagnostic purposes
# (setting this to/tmp is insecure on a multi-user system)
; dump File =/tmp/freetds. log
; debug flags = 0 xFFFF
# command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a text field.
# Try Setting 'text size' to a more reasonable limit
text size = 64512
client charset = UTF-8 # Add
[server2005]
host = 192.168.x.x
Port = 1433
TDS version = 7.2

4. Test the PHP connection to MSSQL
copy Code the code is as follows: try {
$ hostname = '2017. x. x. x'; // note that, unlike above, you must directly use an IP address or host name
$ Port = 1433; // port
$ dbname = "user "; // database name
$ username = "Database"; // user
$ PW = "passwd "; // password
$ DBH = new PDO ("dblib: host = $ hostname: $ port; dbname = $ dbname", "$ username", "$ PW ");
} catch (pdoexception $ e) {
echo "failed to get dB handle :". $ e-> getmessage (). "N";
exit;
}< br> echo 'connent MSSQL succeed';
$ stmt = $ DBH-> P Repare ("select * From z_2010pinjiu_user");
$ stmt-> execute ();
while ($ ROW = $ stmt-> fetch ()) {
print_r ($ row);
}< br> unset ($ DBH); unset ($ stmt);
?>

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.