linux下php+freetds鏈接SQL server2012
官方網站:
http://www.freetds.org
ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
http://www.freetds.org/userguide/choosingtdsprotocol.htm
參看:
https://github.com/lj2007331/lnmp
http://blog.linuxeye.com/31.html
freetds0.91
一.下載
[root@test1 ~]#
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
[root@test1 ~]#
pwd
/root
[root@test1 ~]#
ls
freetds-stable.tgz
二.編譯安裝
[root@test1 ~]#
yum -y install gcc gcc-c++ libxml2-devel openssl-devel pcre-devel curl-devel gd-devel bzip2-devel
[root@test1 ~]#
tar -zxvf freetds-stable.tgz -C /usr/local/src/
[root@test1 ~]#
cd /usr/local/src/freetds-0.91/
[root@test1 freetds-0.91]#
ls
aclocal.m4
config.sub
freetds.spec
Makefile.am
src
AUTHORS
configure
freetds.spec.in
Makefile.in
tds.dox
autogen.sh
configure.ac
include
missing
TODO
BUGS
COPYING
INSTALL
mkinstalldirs
vms
ChangeLog
COPYING.LIB
install-sh
NEWS
win32
compile
depcomp
interfaces
Nmakefile
config.guess
doc
locales.conf
PWD.in
config.log
freetds.conf
ltmain.sh
README
config.rpath
FreeTDS.sln
m4
samples
下面是截取的freetds官方安裝說明
If you've built other GNU projects, building FreeTDS is a fairly straightforward process. We have a terse and verbose description.php
|
FreeTDS is known to build with GNU and BSD make. If you encounter a large number of build errors, and your operating system's make is not GNU make (as is the case on most non-GNU/Linux systems), you may wish to install GNU make from ftp.gnu.org.html |
$ ./configure --prefix=/usr/local
$ make
$ make install
Table 3-1. Versions of the TDS Protocol, by Productlinux
Product |
TDS Version |
Comment |
Sybase before System 10, Microsoft SQL Server 6.x |
4.2 |
Still works with all products, subject to its limitations. |
Sybase System 10 and above |
5.0 |
Still the most current protocol used by Sybase. |
Sybase System SQL Anywhere |
5.0 only |
Originally Watcom SQL Server, a completely separate codebase. Our best information is that SQL Anywhere first supported TDS in version 5.5.03 using the OpenServer Gateway (OSG), and native TDS 5.0 support arrived with version 6.0. |
Microsoft SQL Server 7.0 |
7.0 |
Includes support for the extended datatypes in SQL Server 7.0 (such as char/varchar fields of more than 255 characters), and support for Unicode. |
Microsoft SQL Server 2000 |
7.1 |
Include support for bigint (64 bit integers), variant and collation on all fields. Collation is not widely used. |
Microsoft SQL Server 2005 |
7.2 |
Includes support for varchar(max), varbinary(max), xml datatypes and MARS[a]. |
Microsoft SQL Server 2008 |
7.2 (unchanged) |
|
Notes: a. Multiple Active Result Sets. FreeTDS does not support MARS.
|
For best results, use the highest version of the protocol supported by your server. If you encounter problems, try a lower version. If that works, though, please report it to the mailing list! [1]nginx
[root@test1 freetds-0.91]#
./configure --prefix=/usr/local/freetds --enable-msdblib --with-tdsver=8.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
... ...
config.status: executing depfiles commands
config.status: executing libtool commands
[root@test1 freetds-0.91]#
make && make install
Making all in include
make[1]: Entering directory `/usr/local/src/freetds-0.91/include'
make
all-am
... ...
make[2]: Leaving directory `/usr/local/src/freetds-0.91'
make[1]: Leaving directory `/usr/local/src/freetds-0.91'
編譯php freetds庫支持
[root@test1 freetds-0.91]#
cp include/tds.h /usr/local/freetds/include/
[root@test1 freetds-0.91]#
cp src/tds/.libs/libtds.a /usr/local/freetds/lib
[root@test1 freetds-0.91]#
echo /usr/local/freetds/lib/ >>/etc/ld.so.conf.d/freetds.conf
[root@test1 freetds-0.91]#
ldconfig
[root@test1 freetds-0.91]#
echo "export FREETDSCONF=/usr/local/freetds/etc/freetds.conf" >> /etc/profile
[root@test1 freetds-0.91]#
source /etc/profile
[root@test1 freetds-0.91]#
echo $FREETDSCONF
/usr/local/freetds/etc/freetds.conf
[root@test1 freetds-0.91]#
ln -s /usr/local/freetds/lib /usr/local/freetds/lib64
[root@test1 freetds-0.91]#
vim /usr/local/freetds/etc/freetds.conf
[root@test1 freetds-0.91]#
cat /usr/local/freetds/etc/freetds.conf
#
$Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[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 = 0xffff
# 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
# A typical Sybase server
#[egServer50]
#
host = symachine.domain.com
#
port = 5000
#
tds version = 5.0
# A typical Microsoft server
[SQLserver2008] #標識,無關緊要
host = 192.168.8.112
port = 1433
tds version = 8.0
client charset = UTF-8
[root@test1 freetds-0.91]#
echo 'PATH=$PATH:/usr/local/freetds/bin/' >>/etc/profile
[root@test1 freetds-0.91]#
source /etc/profile
[root@test1 freetds-0.91]#
echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/freetds/bin/
[root@test1 ~]#
freebcp
usage:
freebcp [[database_name.]owner.]table_name {in | out} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n] [-c] [-t field_terminator] [-r row_terminator]
[-U username] [-P password] [-I interfaces_file] [-S server]