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);
?>