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