pdo dblib on centos 6.x

2020-03-04 09:03发布

I am trying to install dblib on CentOS release 6.5 (Final) 64bit. centos 6 does not have freetds so I had to get freetds from elsewhere. freetds-devel-0.91-2.1.x86_64.rpm. using pecl to download and instal PDO DBLIB but i get stuck at make. the error i receive is as follows.

[root@rajesh PDO_DBLIB-1.0]# make
/bin/sh /root/php/PDO_DBLIB-1.0/libtool --mode=compile cc -I/usr/include/php/ext -DPDO_DBLIB_FLAVOUR=\"freetds\" -I. -I/root/php/PDO_DBLIB-1.0 -DPHP_ATOM_INC -I/root/php/PDO_DBLIB-1.0/include -I/root/php/PDO_DBLIB-1.0/main -I/root/php/PDO_DBLIB-1.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /root/php/PDO_DBLIB-1.0/pdo_dblib.c -o pdo_dblib.lo 
libtool: compile:  cc -I/usr/include/php/ext -DPDO_DBLIB_FLAVOUR=\"freetds\" -I. -I/root/php/PDO_DBLIB-1.0 -DPHP_ATOM_INC -I/root/php/PDO_DBLIB-1.0/include -I/root/php/PDO_DBLIB-1.0/main -I/root/php/PDO_DBLIB-1.0 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php/PDO_DBLIB-1.0/pdo_dblib.c  -fPIC -DPIC -o .libs/pdo_dblib.o
In file included from /root/php/PDO_DBLIB-1.0/pdo_dblib.c:32:
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:45:23: error: sybfront.h: No such file or directory
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:46:20: error: sybdb.h: No such file or directory
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:47:23: error: syberror.h: No such file or directory
In file included from /root/php/PDO_DBLIB-1.0/pdo_dblib.c:32:
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:90: error: expected ‘)’ before ‘*’ token
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:93: error: expected ‘)’ before ‘*’ token
/root/php/PDO_DBLIB-1.0/php_pdo_dblib_int.h:110: error: expected specifier-qualifier-list before ‘LOGINREC’
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:76: error: expected ‘)’ before ‘*’ token
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:123: error: expected ‘)’ before ‘*’ token
/root/php/PDO_DBLIB-1.0/pdo_dblib.c: In function ‘zm_startup_pdo_dblib’:
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:175: error: ‘FAIL’ undeclared (first use in this function)
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:175: error: (Each undeclared identifier is reported only once
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:175: error: for each function it appears in.)
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:195: error: ‘error_handler’ undeclared (first use in this function)
/root/php/PDO_DBLIB-1.0/pdo_dblib.c:196: error: ‘msg_handler’ undeclared (first use in this function)
make: *** [pdo_dblib.lo] Error 1


[root@rajesh php]# whereis freetds
freetds: /etc/freetds.conf /usr/include/freetds /usr/local/freetds


[root@rajesh php]# php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_dblib.so' - /usr/lib64/php/modules/pdo_dblib.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

[root@rajesh ~]# rpm -qa | grep freetds
freetds-devel-0.91-1.el6.rf.x86_64
freetds-0.91-1.el6.rf.x86_64

I have tried to change function_entry to zend_function_entry in pdo_dblib.cbut does not work as mentioned in http://www.radebatz.net/mano/2013/11/05/compiling-pdo_dblib-on-centos-6-with-php-5-4/.

I have also tried

[root@rajesh PDO_DBLIB-1.0]# ll /usr/include/freetds
total 132
-rw-r--r-- 1 root root  3054 Feb 19  2013 bkpublic.h
-rw-r--r-- 1 root root 21930 Feb 19  2013 cspublic.h
-rw-r--r-- 1 root root  4847 Feb 19  2013 cstypes.h
-rw-r--r-- 1 root root  7319 Feb 19  2013 ctpublic.h
-rw-r--r-- 1 root root   995 Feb 19  2013 odbcss.h
-rw-r--r-- 1 root root  5086 Feb 19  2013 sqldb.h
-rw-r--r-- 1 root root  1985 Feb 19  2013 sqlfront.h
-rw-r--r-- 1 root root 60728 Feb 19  2013 sybdb.h
-rw-r--r-- 1 root root  1535 Feb 19  2013 syberror.h
-rw-r--r-- 1 root root  1235 Feb 19  2013 sybfront.h
-rw-r--r-- 1 root root  2686 Feb 19  2013 tds_sysdep_public.h
[root@rajesh PDO_DBLIB-1.0]# cp /usr/include/freetds/* /usr/local/freetds/include/
cp: overwrite `/usr/local/freetds/include/bkpublic.h'? n
cp: overwrite `/usr/local/freetds/include/cspublic.h'? n
cp: overwrite `/usr/local/freetds/include/cstypes.h'? n
cp: overwrite `/usr/local/freetds/include/ctpublic.h'? n
cp: overwrite `/usr/local/freetds/include/odbcss.h'? n
cp: overwrite `/usr/local/freetds/include/sqldb.h'? n
cp: overwrite `/usr/local/freetds/include/sqlfront.h'? n
cp: overwrite `/usr/local/freetds/include/sybdb.h'? n
cp: overwrite `/usr/local/freetds/include/syberror.h'? n
cp: overwrite `/usr/local/freetds/include/sybfront.h'? n
cp: overwrite `/usr/local/freetds/include/tds_sysdep_public.h'? n

Seems like it is not picking up the include dir.

I have managed to install PDO DBLIB using the follwoing configure command ./configure --prefix=/usr/local/freetds --with-gnu-ld --with-pdo-dblib=/usr/local/freetds. How ever on my web application i keep getting. CDbConnection failed to open the DB connection: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)

/etc/freetds.conf

[ebenezer]
        host = ebenezer.uk.domain.com
        port = 1433
        tds version = 8.0


[root@rajesh PDO_DBLIB-1.0]# tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 4.2
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: no


[root@rajesh PDO_DBLIB-1.0]# TDSVER=8.0 tsql -S ebenezer -U invload -P invload
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> quit

After a clean up I have managed to somehow come back to

[root@rajesh freetds-0.91]# TDSVER=7.1 /usr/local/freetds/bin/tsql -H ebenezer -U invload -P invlaod -p 1443
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20009 (severity 9):
    Unable to connect: Adaptive Server is unavailable or does not exist
    OS error 111, "Connection refused"
There was a problem connecting to the server
[root@rajesh freetds-0.91]# /usr/bin/ts
tset   tsort  tsql   
[root@rajesh freetds-0.91]# /usr/bin/ts
tset   tsort  tsql   
[root@rajesh freetds-0.91]# /usr/bin/tsql -H ebenezer -U invload -P invlaod -p 1443
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20009 (severity 9):
    Unable to connect: Adaptive Server is unavailable or does not exist
    OS error 111, "Connection refused"
There was a problem connecting to the server


tail: /tmp/freetds.log: file truncated
log.c:196:Starting log file for FreeTDS 0.91
    on 2014-01-24 20:07:55 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0x142c3e0, UTF-8)
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done
net.c:205:Connecting to 172.16.0.71 port 1443 (TDS version 4.2)
net.c:270:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:306:getsockopt(2) reported: Connection refused
net.c:316:tds_open_socket() failed
util.c:331:tdserror(0x142c140, 0x142c3e0, 20009, 111)
util.c:361:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:384:tdserror: returning TDS_INT_CANCEL(2)
mem.c:615:tds_free_all_results()

2条回答
迷人小祖宗
2楼-- · 2020-03-04 09:35

yum install epel-release

yum upgrade ca-certificates --disablerepo=epel

yum install php-mssql

查看更多
该账号已被封号
3楼-- · 2020-03-04 09:42

The easy way to achieve that:

  1. Enable EPEL repository
  2. Install php-mssql. That will install unixODBC and freetds, too.

# yum install php-mssql

Then, you can connect from PHP + PDO (using the dblib driver) from CentOS to your MSSQL server

$dsn = "dblib:host=<host>;dbname=<dbname>";
$user = <user>;
$password = <password>;
$db = new PDO($dsn, $user, $password);

Dockerfile example, but should also work with any CentOS6+ and PHP 7.0:

FROM centos:centos7

RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\
# We include PHP 7 from REMI since it's not in EPEL.
    http://rpms.remirepo.net/enterprise/remi-release-7.rpm\
# This will help verify packages and so you will see fewer errors(red) in the build output.
 && rpm --import \
      /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7\
      /etc/pki/rpm-gpg/RPM-GPG-KEY-remi\
      /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\
# Spedify which version of PHP 7 to install here
 && yum-config-manager --enable remi,remi-php70\
 && yum -y install php-mssql
查看更多
登录 后发表回答