gpt4 book ai didi

pdo - 使用 PDO 连接到 Sybase 的正确 DSN

转载 作者:行者123 更新时间:2023-12-04 16:09:52 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 的 PDO 连接到 Sybase (SQL Anywhere 12) 数据库。我花了几个小时试图找到要使用的正确驱动程序和 DSN,但根本没有成功。每次我尝试编辑单个参数时,总是会出错。我尝试了数十种不同的 DSN 参数组合,没有任何 react 。我将在这里只报告一些只是为了给你我试图获得的例子。

我成功安装了 PDO 驱动程序 - 来自 php.ini:

PDO drivers     dblib, mysql, odbc, pgsql 

PDO Driver for FreeTDS/Sybase DB-lib enabled
Flavour freetds

数据库参数:

数据库的 IP 是 192.168.100.234,数据库实例和数据库名称都是 GAMMA01。我不能告诉你用户名和密码,但让我们说:用户 dba 和 pwd 好吧。
我可以从我尝试启动连接的服务器 ping 服务器。

我在 Linux Debian Squeeze 和 PHP 5.3.3 下。

DBLIB:

我无法找到正确的 DSN 以用于连接到我的数据库服务器。

DSN 版本 1:
'dblib:host=192.168.100.234;DBN=GAMMA01'

DSN 版本 2:
'dblib:host=192.168.100.234;DBN=GAMMA01;UID=dba;PWD=allright;Server=GAMMA01;ASTART=No'

DSN 版本 3:
new PDO('dblib:host=192.168.100.234;dbname=GAMMA01', 'dba', 'allright');

我得到的错误
 SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)

FreeTDS 错误日志(尝试使用 5.0 和 7.0 版本,没有区别):
log.c:190:Starting log file for FreeTDS 0.82
on 2014-04-08 13:40:40 with debug flags 0x4fff.
iconv.c:363:iconv to convert client-side data to the "ANSI_X3.4-1968" character set
iconv.c:516:tds_iconv_info_init: converting "US-ASCII"->"UCS-2LE"
iconv.c:516:tds_iconv_info_init: converting "ISO-8859-1"->"UCS-2LE"
net.c:210:Connecting to 192.168.100.234 port 5200 (TDS version 7.0)
net.c:264:tds_open_socket: connect(2) returned "Operation now in progress"
net.c:299:getsockopt(2) reported: Connection refused
util.c:334:tdserror(0xb9a46eb0, 0xb9b60688, 20009, 115)
dblib.c:7782:dbperror(0xb9b5ff88, 20009, 115)
dblib.c:7835:20009: "Unable to connect: Adaptive Server is unavailable or does not exist"
dblib.c:5627:dbgetuserdata(0xb9b5ff88)
dblib.c:7856:"Unable to connect: Adaptive Server is unavailable or does not exist", client returns 2 (INT_CANCEL)
util.c:368:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:389:tdserror: returning TDS_INT_CANCEL(2)
net.c:310:tds_open_socket() failed
dblib.c:1372:dbclose(0xb9b5ff88)
dblib.c:256:dblib_del_connection(0xb5ceea00, 0xb9b60688)
mem.c:563:tds_free_all_results()
dblib.c:303:dblib_release_tds_ctx(1)
dblib.c:5727:dbfreebuf(0xb9b5ff88)
dblib.c:718:dbloginfree(0xb9b46588)

使用 sybase:DSN:
'sybase:host=192.168.100.234;dbname=GAMMA01, dba, allright'

错误:
could not find driver

ODBC:
我无法连接 ODBC 驱动程序。我在这里阅读指南: http://www.sybase.com/files/White_Papers/PHP_SQL_Anywhere.pdf并在此处下载正确的 .so 包: http://scn.sap.com/docs/DOC-40537但我无法让 PHP 识别该包,加载它并使用它。

DSN:
'odbc:Driver={Sybase SQL Anywhere 12};NA=192.168.100.234,5200;Uid=dba;Pwd=allright;'
'odbc:Driver={SQL Anywhere 12};NA=192.168.100.234,5200;Uid=dba;Pwd=allright;'
'odbc:DRIVER={Sybase SQL Anywhere 12};SRVR=192.168.100.234;DB=gamma01;UID=dba;PWD=allright;'
'odbc:DRIVER={Sybase SQL Anywhere 12};HOSTNAME=192.168.100.234;DATABASE=gamma01;UID=dba;PWD=allright;PROTOCOL:TCPIP'

我得到的错误:
SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified

我应该使用哪个驱动程序连接到 Sybase 数据库?哪个是正确的 DSN?

最佳答案

"Data source name not found and no default driver specified."错误意味着在 中找不到您指定的 DSN 或驱动程序。 odbc.ini ODBC 环境的文件。

您需要确保您的 ODBC 环境设置正确。通常,这包括 的位置和文件名的规范。 odbc.ini 文件。

尝试连接时,将搜索 odbc.ini 文件以查找匹配的数据源名称 (DSN)

在您的情况下,您指定的是“驱动程序”。这是通常在 中找到的类似配置。 odbcinst.ini 文件;也由您的 ODBC 环境指定。

要检查的另一件事是确保正在运行的进程或您的 PHP 应用程序的拥有用户找到 ODBC 环境。

关键是要弄清楚连接序列的哪一部分失败了。在您的情况下,成功的连接将遵循以下路径:

  • 申请开始
  • 尝试 ODBC 连接
  • 搜索 ODBC Environment 以找到配置文件(通常为“驱动程序”配置的 odbcinst.ini)
  • 在连接字符串
  • 中查找为“Driver=”指定的值的匹配项
  • 使用找到的驱动程序部分中配置的值以及连接字符串中提供的其他选项尝试连接。

  • 导致您收到错误的两个主要因素是:
  • 未配置 ODBC 环境
  • DSN 或驱动程序值拼写不正确。

  • 我希望这有帮助。

    托尼·霍尔

    关于pdo - 使用 PDO 连接到 Sybase 的正确 DSN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22936157/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com