通过dblib使用php 5.2.6 on centos连接到MSSQL SERVER 2012

时间:2013-02-28 15:47:49

标签: php sql-server zend-framework pdo yii

我正在使用php 5.2.4在centos 32bit操作系统上使用zend框架测试我与MS SQL Server的连接。我在try catch子句

上收到错误消息
            try {
        $db->getConnection();
    } catch( Exception $e ) {
        print_r($e->getMessage());
        die;
    }

The mssql driver is not currently installed

我的application.ini文件

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
phpSettings.date.timezone = "Europe/London"

resources.multidb.local.adapter = "PDO_MSSQL"
resources.multidb.local.host = ICHIGO
resources.multidb.local.username = Administrator
resources.multidb.local.password = xxx
resources.multidb.local.dbname = Navision
resources.multidb.local.isDefaultTableAdapter = true
resources.multidb.local.default = true

resources.frontController.baseUrl = "/invload"
resources.view[] = ""
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view.doctype = "XHTML1_STRICT"

ldap.log_path = ../logs/invload.log
log.path = APPLICATION_PATH "/../logs/invload.log"
log.level = 7


[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
log.level = 7

我安装了freetds

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

PHPINFO

解析了其他.ini文件

 /etc/php.d/bcmath.ini, /etc/php.d/dba.ini, /etc/php.d/dbase.ini, /etc/php.d/dom.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/ldap.ini, /etc/php.d/mbstring.ini, /etc/php.d/mcrypt.ini, /etc/php.d/mhash.ini, /etc/php.d/mssql.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/ncurses.ini, /etc/php.d/odbc.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_odbc.ini, /etc/php.d/pdo_pgsql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/pgsql.ini, /etc/php.d/snmp.ini, /etc/php.d/soap.ini, /etc/php.d/tidy.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlrpc.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini 
mssql
MSSQL Support   enabled
Active Persistent Links     0
Active Links    0
Library version     FreeTDS

Directive   Local Value Master Value
mssql.allow_persistent  On  On
mssql.batchsize 0   0
mssql.charset   no value    no value
mssql.compatability_mode    Off Off
mssql.connect_timeout   5   5
mssql.datetimeconvert   On  On
mssql.max_links Unlimited   Unlimited
mssql.max_persistent    Unlimited   Unlimited
mssql.max_procs Unlimited   Unlimited
mssql.min_error_severity    10  10
mssql.min_message_severity  10  10
mssql.secure_connection Off Off
mssql.textlimit Server default  Server default
mssql.textsize  Server default  Server default
mssql.timeout   60  60

PDO
PDO support enabled
PDO drivers     mysql, odbc, pgsql, sqlite 

以下是我的配置选项。我需要更改什么才能启用PDO MSSQL

'./configure' '--host=i686-redhat-linux-gnu' '--build=i686-redhat-linux-gnu' '--target=i386-redhat-linux' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json' 

另外

我输入resources.multidb.local.pdoType = "dblib"后。我现在遇到SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)抛出的问题$db->getConnection();。我已阅读this并尝试补充

我有以下文件。我使用或编辑哪一个

find . -name odbc.ini
./root/php/freetds-0.91/samples/odbc.ini
./usr/local/unixODBC/etc/odbc.ini
./usr/local/etc/odbc.ini
./usr/share/doc/freetds-devel-0.64/samples/odbc.ini
./etc/php.d/odbc.ini
./etc/odbc.ini
./var/tmp/php-5.2.6-2-root-root/etc/php.d/odbc.ini
/root/php/freetds-0.91/freetds.conf
/usr/local/freetds/etc/freetds.conf
/usr/local/etc/freetds.conf
/etc/freetds.conf

我的freetds.log提供以下信息

   [root@portal-test opt]# TDSDUMPCONFIG=stdout  TDSDUMP=stdout tsql -S xyz -U sharifu -P xxx
log.c:196:Starting log file for FreeTDS 0.91
    on 2013-03-15 14:57:55 with debug flags 0x4fff.
config.c:185:Getting connection information for [xyz].
config.c:189:Attempting to read conf files.
config.c:354:... $FREETDSCONF not set.  Trying $FREETDS/etc.
config.c:367:... $FREETDS not set.  Trying $HOME.
config.c:293:Could not open '/root/.freetds.conf' ((.freetds.conf)).
config.c:297:Found conf file '/usr/local/etc/freetds.conf' (default).
config.c:483:Looking for section global.
config.c:540:   Found section global.
config.c:543:Got a match.
config.c:565:   tds version = '8'
config.c:565:   dump file = '/var/log/freetds.log'
config.c:565:   debug flags = '0xffff'
config.c:565:   text size = '64512'
config.c:540:   Found section egserver50.
config.c:540:   Found section xyz.
config.c:554:   Reached EOF
config.c:483:Looking for section xyz.
config.c:540:   Found section global.
config.c:540:   Found section egserver50.
config.c:540:   Found section xyz.
config.c:543:Got a match.
config.c:565:   host = 'ichigo'
config.c:595:Found host entry ichigo.
config.c:599:IP addr is 172.16.0.85.
config.c:565:   port = '1433'
config.c:554:   Reached EOF
config.c:301:Success: [xyz] defined in /usr/local/etc/freetds.conf.
config.c:714:Setting 'dump_file' to 'stdout' from $TDSDUMP.
config.c:224:Final connection parameters:
config.c:225:            server_name = xyz
config.c:226:       server_host_name = ichigo
config.c:227:                ip_addr = 172.16.0.85
config.c:228:          instance_name = 
config.c:229:                   port = 1433
config.c:230:          major_version = 5
config.c:231:          minor_version = 0
config.c:232:             block_size = 0
config.c:233:               language = us_english
config.c:234:         server_charset = iso_1
config.c:235:        connect_timeout = 0
config.c:236:       client_host_name = portal-test.uk.domain.com
config.c:237:         client_charset = UTF-8
config.c:238:               app_name = TSQL
config.c:239:              user_name = sharifu
config.c:242:                library = TDS-Library
config.c:243:              bulk_copy = 0
config.c:244:      suppress_language = 0
config.c:245:          encrypt level = 0
config.c:246:          query_timeout = 0
config.c:249:               database = 
config.c:250:              dump_file = stdout
config.c:251:            debug_flags = ffff
config.c:252:              text_size = 64512
config.c:253:           broken_dates = 0
config.c:254:     emul_little_endian = 0
config.c:255:      server_realm_name = 
14:57:55.027461 10945 (log.c:196):Starting log file for FreeTDS 0.91
    on 2013-03-15 14:57:55 with debug flags 0xffff.
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
14:57:55.028231 10945 (iconv.c:330):tds_iconv_open(0x994da78, UTF-8)
14:57:55.028554 10945 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
14:57:55.028565 10945 (iconv.c:187):local name for UTF-8 is UTF-8
14:57:55.028572 10945 (iconv.c:187):local name for UCS-2LE is UCS-2LE
14:57:55.028579 10945 (iconv.c:187):local name for UCS-2BE is UCS-2BE
14:57:55.028585 10945 (iconv.c:349):setting up conversions for client charset "UTF-8"
14:57:55.028592 10945 (iconv.c:351):preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
14:57:55.028611 10945 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
14:57:55.028621 10945 (iconv.c:394):tds_iconv_open: done
14:57:55.028630 10945 (net.c:205):Connecting to 172.16.0.85 port 1433 (TDS version 5.0)
14:57:55.028877 10945 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"
14:57:55.029114 10945 (net.c:310):tds_open_socket() succeeded
14:57:55.029134 10945 (util.c:156):Changed query state from DEAD to IDLE
14:57:55.029153 10945 (net.c:741):Sending packet
0000 02 00 02 00 00 00 00 00-70 6f 72 74 61 6c 2d 74 |........ portal-t|
0010 65 73 74 2e 75 6b 2e 73-70 65 63 74 72 75 6d 61 |est.uk.s pectruma|
0020 73 61 2e 63 6f 6d 1e 73-68 61 72 69 66 75 00 00 |sa.com.s harifu..|
0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0040 00 00 00 00 00 07 77 6f-6b 69 6e 67 00 00 00 00 |......wo king....|
0050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0060 00 00 00 00 06 31 30 39-34 35 00 00 00 00 00 00 |.....109 45......|
0070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0080 00 00 00 05 03 01 06 0a-09 01 00 00 00 00 00 00 |........ ........|
0090 00 00 00 00 54 53 51 4c-00 00 00 00 00 00 00 00 |....TSQL ........|
00a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00b0 00 00 04 78 79 7a 00 00-00 00 00 00 00 00 00 00 |...xyz.. ........|
00c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00d0 00 03 00 06 77 6f 6b 69-6e 67 00 00 00 00 00 00 |....woki ng......|
00e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
00f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0100 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0110 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01a0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01b0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01c0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
01d0 00 08 05 00 00 00 54 44-53 2d 4c 69 62 72 61 72 |......TD S-Librar|
01e0 0a 05 00 00 00 00 0d 11-75 73 5f 65 6e 67 6c 69 |........ us_engli|
01f0 73 68 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |sh...... ........|

14:57:55.031016 10945 (net.c:741):Sending packet
0000 02 01 00 61 00 00 00 00-00 00 00 00 00 00 0a 00 |...a.... ........|
0010 00 00 00 00 00 00 00 00-00 00 00 00 00 69 73 6f |........ .....iso|
0020 5f 31 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |_1...... ........|
0030 00 00 00 00 00 00 00 00-00 00 00 05 01 35 31 32 |........ .....512|
0040 00 00 00 03 00 00 00 00-e2 16 00 01 09 00 08 0e |........ ........|
0050 6d 7f ff ff ff fe 02 09-00 00 00 00 02 68 00 00 |m....... .....h..|
0060 00                     -                        |.|

14:57:55.031414 10945 (token.c:328):tds_process_login_tokens()
14:57:55.032354 10945 (util.c:331):tdserror(0x994d8d0, 0x994da78, 20017, 115)
Error 20017 (severity 9):
    Unexpected EOF from the server
    OS error 115, "Operation now in progress"
14:57:55.032667 10945 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
14:57:55.032770 10945 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
14:57:55.032921 10945 (util.c:156):Changed query state from IDLE to DEAD
14:57:55.033007 10945 (token.c:337):looking for login token, got  0()
14:57:55.033223 10945 (token.c:122):tds_process_default_tokens() marker is 0()
14:57:55.033344 10945 (token.c:125):leaving tds_process_default_tokens() connection dead
14:57:55.033430 10945 (login.c:466):login packet accepted
14:57:55.033538 10945 (util.c:331):tdserror(0x994d8d0, 0x994da78, 20002, 0)
Error 20002 (severity 9):
    Adaptive Server connection failed
14:57:55.033721 10945 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
14:57:55.033834 10945 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
14:57:55.033905 10945 (mem.c:615):tds_free_all_results()
There was a problem connecting to the server

以下脚本会出现以下错误

$serverName = "ichigo";
$databaseName = "Navision";
$username = "sharifu";
$password = "woking";
$mssql = new PDO("dblib:host=$serverName;dbname=$databaseName", $username, $password );

错误:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)' in /opt/pdo.php:8
Stack trace:
#0 /opt/pdo.php(8): PDO->__construct('dblib:host=ichi...', 'sharifu', 'woking')
#1 {main}
  thrown in /opt/pdo.php on line 8

freetds.log

15:42:14.398739 11156 (log.c:196):Starting log file for FreeTDS 0.91
    on 2013-03-15 15:42:14 with debug flags 0xffff.
15:42:14.398816 11156 (iconv.c:330):tds_iconv_open(0x9589c30, UTF-8)
15:42:14.399018 11156 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
15:42:14.399031 11156 (iconv.c:187):local name for UTF-8 is UTF-8
15:42:14.399039 11156 (iconv.c:187):local name for UCS-2LE is UCS-2LE
15:42:14.399047 11156 (iconv.c:187):local name for UCS-2BE is UCS-2BE
15:42:14.399054 11156 (iconv.c:349):setting up conversions for client charset "UTF-8"
15:42:14.399062 11156 (iconv.c:351):preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
15:42:14.399082 11156 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
15:42:14.399093 11156 (iconv.c:394):tds_iconv_open: done
15:42:14.399103 11156 (net.c:205):Connecting to 172.16.0.85 port 4000 (TDS version 5.0)
15:42:14.399193 11156 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"
15:42:19.398885 11156 (net.c:316):tds_open_socket() failed
15:42:19.398990 11156 (util.c:331):tdserror(0x94add08, 0x9589c30, 20009, 115)
15:42:19.399070 11156 (dblib.c:7929):dbperror(0x95894d0, 20009, 115)
15:42:19.399097 11156 (dblib.c:7981):20009: "Unable to connect: Adaptive Server is unavailable or does not exist"
15:42:19.399137 11156 (dblib.c:5780):dbgetuserdata(0x95894d0)
15:42:19.399151 11156 (dblib.c:8002):"Unable to connect: Adaptive Server is unavailable or does not exist", client returns 2 (INT_CANCEL)
15:42:19.399160 11156 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
15:42:19.399168 11156 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
15:42:19.399179 11156 (dblib.c:1443):dbclose(0x95894d0)
15:42:19.399187 11156 (dblib.c:258):dblib_del_connection(0xe30680, 0x9589c30)
15:42:19.399201 11156 (mem.c:615):tds_free_all_results()
15:42:19.399214 11156 (dblib.c:305):dblib_release_tds_ctx(1)
15:42:19.399232 11156 (dblib.c:5882):dbfreebuf(0x95894d0)
15:42:19.399537 11156 (dblib.c:739):dbloginfree(0x9589428)
15:42:19.400757 11156 (dblib.c:1512):dbexit(void)
15:42:19.401383 11156 (dblib.c:1512):dbexit(void)
15:42:19.401401 11156 (dblib.c:305):dblib_release_tds_ctx(1)

在日志中,您可以看到端口提到4000这是错误的,因此是TDS VERSION。我目前的freetds配置文件内容如下:

[global]
        # TDS protocol version
;   tds version = 8

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (setting this to /tmp is insecure on a multi-user system)
    dump file = /var/log/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
[xyz]
    host = ichigo
    port = 1433
    tds version = 7.0

我无法解决的错误是SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)。更新到日期的PHP设置是:

[root@portal-test /]# php -m | grep -i pdo
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite

[root@portal-test opt]# php -r "phpinfo();" | grep -i pdo
Configure Command =>  './configure'  '--host=i686-redhat-linux-gnu' '--build=i686-redhat-linux-gnu' '--target=i386-redhat-linux' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--enable-force-cgi-redirect' '--enable-pcntl' '--with-imap=shared' '--with-imap-ssl' '--enable-mbstring=shared' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-ncurses=shared' '--with-gd=shared' '--enable-bcmath=shared' '--enable-dba=shared' '--with-db4=/usr' '--with-xmlrpc=shared' '--with-ldap=shared' '--with-ldap-sasl' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--enable-dom=shared' '--with-dom-xslt=/usr' '--with-dom-exslt=/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--with-xsl=shared,/usr' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--enable-fastcgi' '--enable-pdo=shared' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-mysql=shared,/usr' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--enable-json=shared' '--enable-zip=shared' '--with-readline' '--enable-dbase=shared' '--with-mcrypt=shared,/usr' '--with-mhash=shared,/usr' '--with-tidy=shared,/usr' '--with-mssql=shared,/usr'
/etc/php.d/pdo.ini,
/etc/php.d/pdo_dblib.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_odbc.ini,
/etc/php.d/pdo_pgsql.ini,
/etc/php.d/pdo_sqlite.ini,
PDO
PDO support => enabled
PDO drivers => dblib, mysql, odbc, pgsql, sqlite
pdo_dblib
PDO Driver for FreeTDS/Sybase DB-lib => enabled
pdo_mysql
PDO Driver for MySQL, client library version => 5.0.95
PDO_ODBC
PDO Driver for ODBC (unixODBC) => enabled
pdo_pgsql
PDO Driver for PostgreSQL => enabled
Revision =>  $Id: pdo_pgsql.c,v 1.7.2.11.2.1 2007/01/01 09:36:05 sebastian Exp $ 
pdo_sqlite
PDO Driver for SQLite 3.x => enabled
PECL Module version => 1.0.1 $Id: pdo_sqlite.c,v 1.10.2.6.2.2 2007/03/23 14:30:00 wez Exp $

解决

我遵循了以下guide。要在this之后安装dblib i。然后设置freetds。这适用于一个新的centos安装,但我当前的盒子仍然有问题,端口号不会因为奇怪的随机原因而改变,我想我可能已经腐败了。

3 个答案:

答案 0 :(得分:2)

需要在php中启用驱动程序。看看你的php.ini设置,并确保你正在加载模块。 您可以通过调用phpinfo()函数来检查配置。

您已启用mssql扩展程序,但我看不到PDO扩展程序。我没有一个centos盒子,所以我无法测试它,但我认为你可以用yum安装PDO。

yum install php-pdo

在您的配置中,您有'--disable-pdo',但我认为您不需要重新编译。只需将其添加到php.ini

即可
; Extension PDO
  extension=pdo.so

答案 1 :(得分:0)

  

net.c:306:getsockopt(2) reported: Connection timed out

日志之前的那一行是什么?它应该说出名称/地址,端口和TDS版本。如果它不是名字&amp;托管SQL Server的计算机的端口,然后您的freetds.conf错误或(经常发生)具有阻止PHP进程读取它的权限。

为了证明,您可以设置TDSDUMPCONFIG以获取FreeTDS搜索以解析服务器名称及其发现的内容的日志。

答案 2 :(得分:0)

这对我有用:

/etc/freetds.conf

[mydb]
host = myserver.example.com
#port = 1434
tds version = auto
client charset = UTF-8