【问题标题】:How can I connect to Sybase using FreeTDS?如何使用 FreeTDS 连接到 Sybase?
【发布时间】:2011-06-16 07:14:49
【问题描述】:

我的 freetds.conf

# /usr/local/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
[egServer70]
    host = ntmachine.domain.com
    port = 1433
    tds version = 7.0

[myserver]
    host = myserver.com
    port = 5000
    tds version = 5.0

我的sybase.php

<?php

$server = 'myserver';
$user   = 'user';
$pwd    = 'pwd';
$db     = 'db';

@sybase_connect($server, $user, $pwd) or die('Cannot connect');

echo "OK\n";

当我通过 CLI php sybase.php 运行它时,它工作得很好。但是当我通过网络服务器运行它时它不会连接。 有人知道我的代码有什么问题吗?

我也试过放

putenv("FREETDSCONF=/usr/local/etc/freetds.conf");

但是什么也没发生,我什至尝试在sybase_connect() 之前输入错误的路径到freetds.conf 并且代码仍然可以正常运行(使用php sybase.php 但不是通过网络服务器)。

顺便说一句,每次我重新启动我的 apache 时都会遇到这些错误:

<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/php_sybase_ct.dll' - /usr/lib/php/extensions/php_sybase_ct.dll: cannot open shared object file: No such file or directory in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/php_sybase_ct.dll' - /usr/lib/php/extensions/php_sybase_ct.dll: cannot open shared object file: No such file or directory in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/php_sybase_ct.dll' - /usr/lib/php/extensions/php_sybase_ct.dll: invalid ELF header in <b>Unknown</b> on line <b>0</b><br />
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/php_sybase_ct.dll' - /usr/lib/php/extensions/php_sybase_ct.dll: invalid ELF header in <b>Unknown</b> on line <b>0</b><br />

我没有在我的php.ini 中取消注释;extension=php_sybase_ct.dll,因为我在Linux 中工作。我检查了我的phpinfo(),我可以在其中看到sybase_ct 部分。我使用这些参数构建了我的 PHP:

'./configure' '--with-apxs2=/usr/sbin/apxs' '--prefix=/usr' '--libdir=/usr/lib' '--with-libdir=lib' '--sysconfdir=/etc' '--disable-safe-mode' '--disable-magic-quotes' '--enable-zend-multibyte' '--enable-mbregex' '--enable-tokenizer=shared' '--with-config-file-scan-dir=/etc/php' '--with-config-file-path=/etc/httpd' '--enable-mod_charset' '--with-layout=PHP' '--enable-sigchild' '--enable-xml' '--with-libxml-dir=/usr' '--enable-simplexml' '--enable-spl' '--enable-filter' '--disable-debug' '--with-openssl=shared' '--with-pcre-regex=/usr' '--with-zlib=shared,/usr' '--enable-bcmath=shared' '--with-bz2=shared,/usr' '--enable-calendar=shared' '--enable-ctype=shared' '--with-curl=shared' '--with-curlwrappers' '--with-mcrypt=/usr' '--enable-dba=shared' '--with-gdbm=/usr' '--with-db4=/usr' '--enable-exif=shared' '--enable-ftp=shared' '--with-gd=shared' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-zlib-dir=/usr' '--with-xpm-dir=/usr' '--with-freetype-dir=/usr' '--with-t1lib=/usr' '--enable-gd-native-ttf' '--enable-gd-jis-conv' '--with-gettext=shared,/usr' '--with-gmp=shared,/usr' '--with-iconv=shared' '--with-imap-ssl=/usr' '--with-imap=/usr/local/lib/c-client' '--with-ldap=shared' '--enable-mbstring=shared' '--enable-hash' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--enable-pdo=shared' '--with-pdo-mysql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-pspell=shared,/usr' '--with-enchant=shared,/usr' '--with-mm=/usr' '--enable-shmop=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--enable-sockets' '--with-sqlite=shared' '--enable-sqlite-utf8' '--with-regex=php' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx=shared' '--with-xsl=shared,/usr' '--enable-zip=shared' '--with-tsrm-pthreads' '--enable-shared=yes' '--enable-static=no' '--with-gnu-ld' '--with-pic' '--with-sybase-ct=/usr/local/' '--build=i486-slackware-linux'

【问题讨论】:

    标签: php sybase freetds


    【解决方案1】:

    刚刚解决了问题。显然,我需要这样做:

    1. 确保日志文件对其他人可写chmod o+w /tmp/freetds.log
    2. 我在配置文件中不能使用域名,我必须使用服务器的 IP 地址

    我的新/usr/local/etc/freetds.conf

    [myserver]
        host = 10.10.10.10
        port = 5000
        tds version = 5.0
    

    /tmp/freetds.log 使用域名时出现的错误:

    config.c:257:Success: [myserver] defined in /usr/local/etc/freetds.conf.
    iconv.c:363:iconv to convert client-side data to the "ISO-8859-1" character set
    iconv.c:516:tds_iconv_info_init: converting "ISO-8859-1"->"UCS-2LE"
    login.c:405:IP address pointer is empty
    login.c:407:Server myserver not found!
    

    p/s:我不确定我做了什么,但我没有收到错误 PHP 尝试加载 php_sybase_ct.dll 了。

    【讨论】:

      猜你喜欢
      • 2017-02-18
      • 2019-12-12
      • 1970-01-01
      • 2011-02-24
      • 1970-01-01
      • 2014-11-06
      • 2018-04-30
      • 1970-01-01
      • 2020-05-14
      相关资源
      最近更新 更多