The method of installing the MSSQL module in PHP under Linux _linux

Source: Internet
Author: User
Tags mssql stmt
1, installation configuration FreeTDS
Copy Code code 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 PHP's MSSQL module
Copy Code code as follows:

Cd/path/to/php/source into the PHP source directory
CD Ext/mssql into the MSSQL module source directory
/usr/local/webserver/php/bin/phpize Build Compilation configuration file
./configure–with-php-config=/usr/local/webserver/php/bin/php-config–with-mssql=/usr/local/freetds
Make
Make install
Compile to complete the build mssql.so, modify the php.ini, and load the module into:
extension= "/path/to/extension/mssql.so"

3. Configure MSSQL
Copy Code code 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 the file for diagnostic purposes
# (Setting this to/tmp are insecure on a multi-user system)
; dump file =/tmp/freetds.log
; Debug flags = 0xFFFF
# Command and Connection Timeouts
; Timeout = 10
; Connect Timeout = 10
# If you have 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 #加入
#加入
[Server2005]
Host = 192.168.x.x
Port = 1433
TDS Version = 7.2

4. Test PHP Connection MSSQL
Copy Code code as follows:

<?php
try {
$hostname = ' 218.x.x.x ';/Note that this is different from the above, directly using the IP address or host name br> $port =1433;//port
$dbname = "user";//library name
$username = "database";//user
$PW = "passwd";//password
$DBH = new PDO (" dblib:host= $hostname: $port;d bname= $dbname "," $username "," $PW ");
} catch (Pdoexception $e) {
echo Failed to get DB handle: ". $e->getmessage ()." n ";
Exit;
}
Echo ' connent MSSQL succeed ';
$stmt = $dbh->prepare ("SELECT * from Z_2010pinjiu_user");
$stmt->execute ();
while ($row = $stmt->fetch ()) {
Print_r ($row);
}
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.