gpt4 book ai didi

php - 连接到 MSSQL 数据库时出现问题

转载 作者:搜寻专家 更新时间:2023-10-31 21:57:34 26 4
gpt4 key购买 nike

我有一个 Ubuntu 12.04 服务器,我正在尝试建立与 MSSQL 数据库的连接。

我已经设法使用 tsqlisql 进行连接,但是 osql 不起作用,并且使用 PDO 与 PHP 连接也是'无法正常工作。我会尽力提供尽可能多的信息,如果您需要更多信息,请告诉我,我会进行编辑。

freetds.conf:

[MSSQL]
host = TPSACC
port = 54488
tds version = 8.0

odbc.ini:

[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488

odbcinst.ini:

[FreeTDS]
Description = ODBC for Microsoft SQL
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1
Threading = 2

~> isql MSSQL sa pass

+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

~> tsql -S MSSQL -U 'sa' -P 'pass'

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>

~> osql -S MSSQL -U sa -P pass

checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
trying /tmp/sql ... no
trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
reading /home/toolplas/.odbc.ini
[MSSQL] not found in /home/toolplas/.odbc.ini
reading /etc/odbc.ini
[MSSQL] found in /etc/odbc.ini
found this section:
[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488
looking for driver for DSN [MSSQL] in /etc/odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [MSSQL] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libtdsodbc.so"
found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
"Server" found, not using freetds.conf
Server is "TPSACC"
osql: no IP address found for "TPSACC"

在 PHP 中我有:

$conn = new PDO ("dblib:host=TPSACC;dbname=PRODUCTION","$username","$pw");

..或..

$conn = new PDO ("dblib:host=TPSACC;port=54488;dbname=PRODUCTION","$username","$pw");

他们都返回这个错误:

SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9) 

我已经被困在这里几天了,无法完全弄清楚为什么只有一半的连接真正有效..

非常感谢任何和所有的帮助,谢谢!

编辑:这与那个问题不同,我在评论中解释过,但会在此处重新发布:

对于那个,问题是端口从 1433 更改了。我的也更改了,我修复了它,端口现在是 54488,自从那个更改 tsql 和 isql 一直在工作。但是,它仍然没有解决 osql 和 PHP 问题。

最佳答案

osql 因配置中的某些内容而阻塞。 osql 是一个调试实用程序,它只检查您的配置,然后传递给 unixODBC 的 isql 进行连接 (http://linux.die.net/man/1/osql)。为您的 odbc.ini 试试这个:

[MSSQL]
Driver = FreeTDS
Description = MS SQL connection to PRODUCTION database
Server = tpsacc.yourfulldomain.com
Port = 54488
TDS_Version = 7.2
Database = PRODUCTION
UserName = sa
Password = pass
Trace = No

此外,您确定这是 libtdsodbc.so 的正确位置吗?当我使用 Ubuntu 14 x64 (utopic) 安装 freetds-dev 时,它会安装到/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so;示例 odbcinst.ini:

[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

为了更好地衡量,我使用的典型 freetds.conf:

# A typical Microsoft server
[MSSQL]
host = tpsacc.yourfulldomain.com
port = 54488
tds version = 7.2

FreeTDS 最多只支持 TDS 7.2 版和大多数语言。虽然使用“8.0”应该不会破坏任何东西,但使用 7.2 更利于保持一致性。如果您需要查看引用,我有一个带有完整配置的 Vagrant 盒子,这里有示例:https://github.com/FlipperPA/django-python3-vagrant/祝你好运!

关于php - 连接到 MSSQL 数据库时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31942657/

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