centos 6.x 上的 pdo dblib

Posted

技术标签:

【中文标题】centos 6.x 上的 pdo dblib【英文标题】:pdo dblib on centos 6.x 【发布时间】:2014-02-14 10:11:53 【问题描述】:

我正在尝试在 CentOS 版本 6.5(最终版)64 位上安装 dblib。 centos 6没有freetds,所以我不得不从其他地方获取freetds。 freetds-devel-0.91-2.1.x86_64.rpm。使用 pecl 下载和安装 PDO DBLIB,但我卡在 make 上。我收到的错误如下。

[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

我已尝试将pdo_dblib.c 中的function_entry 更改为zend_function_entry,但没有如http://www.radebatz.net/mano/2013/11/05/compiling-pdo_dblib-on-centos-6-with-php-5-4/ 中所述那样工作。

我也试过

[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

似乎它没有选择包含目录。

我已经设法使用以下配置命令./configure --prefix=/usr/local/freetds --with-gnu-ld --with-pdo-dblib=/usr/local/freetds 安装了 PDO DBLIB。我如何在我的网络应用程序上不断获得。 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

经过一番清理,我设法以某种方式回到

[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()

【问题讨论】:

您还需要安装 FreeTDS 开发文件 (freetds-devel)。 freetds-devel 是使用其他地方的存储库安装的 【参考方案1】:

实现这一目标的简单方法:

    启用 EPEL 存储库 安装php-mssql。这也会安装unixODBCfreetds

# yum install php-mssql

然后,您可以从 CentOS 的 PHP + PDO(使用 dblib 驱动程序)连接到您的 MSSQL 服务器

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

Dockerfile 示例,但也应适用于任何 CentOS6+ 和 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

【讨论】:

centos 7 无法安装 php-mssql 这适用于我在一个以 centos7 和 php7 为基础的 docker 容器中。【参考方案2】:

yum install epel-release

yum 升级 ca-certificates --disablerepo=epel

yum 安装 php-mssql

【讨论】:

以上是关于centos 6.x 上的 pdo dblib的主要内容,如果未能解决你的问题,请参考以下文章

zabbix 2.2.2在centos 6.3 x86_64上的安装

如何配置 php 以在 CentOS 上启用 pdo 并包含 mysqli?

CentOS-6.x系列查看cpu核数

CentOS-6.x系列查看cpu核数

CentOS 6.x下安装VMWare-tools操作指引

RHEL 6.5 X86_64配置CentOS yum源