1 安装freetds(0.64版本)
# tar xvfz freetds-stable.tgz
# cd freetds-0.64
#
./configure --prefix=/usr/local/freetds --with-atdsver=8.0
--enable-msdblib --enable-dbmfix --with-gnu-ld --enable-shared
--enable-static
# make
# make install
以下4步可选
# vi /usr/local/freetds/etc/freetds.conf
[MY_SQLSERVER]
host = 192.168.2.9
port = 1433
tds version = 8.0
client charset = cp936
# vi /usr/local/freetds/interfaces
MY_SQLSERVER
query tcp ether 192.168.2.9 1433
master tcp ether 192.168.2.9 1433
# vi /etc/ld.so.conf
加入/usr/local/freetds/lib
# ldconfig
2 安装php
# tar xvfj php-5.2.3.tar.bz2
# cd php-5.2.3
#
./configure --prefix=/usr/local/php --with-mysql=/usr
--with-apxs=/usr/local/apache2/bin/apxs --with-zlib --with-gd
--with-jpeg-dir --with-mail --with-mssql=/usr/local/freetds
# make
# make install
# cp /usr/local/src/php-5.2.3/php.ini-dist /usr/local/php/lib/php.ini
# 在/usr/local/php/lib/php.ini后加入mssql.charset = "GBK"
3 php代码
# vi test.php
set_time_limit(10);
//phpinfo();
//exit;
$db = mssql_connect("192.168.2.9", "dbuser", "dbuser");
mssql_select_db("dbname", $db);
$query = mssql_query("select * from smitems", $db);
if ($query){
while($arr = mssql_fetch_array($query))
{ print_r($arr);
echo "
";
}
}
mssql_free_result($query);mssql_close($db);
?>
对于报错
touch /usr/local/freetds/include/tds.h
touch l/usr/local/freetds/lib/libtds.a
如果数据库数据出现乱码
在[global]
client charset = utf-8
阅读(1791) | 评论(0) | 转发(1) |