gpt4 book ai didi

tsql - CentOS 6.7 和 Windows MSSQL 连接 - FreeTDS 和 PHP

转载 作者:行者123 更新时间:2023-12-04 19:31:30 33 4
gpt4 key购买 nike

我搜索了与我的问题相关的答案,但没有找到我正在寻找的内容。

我有 Linux CentOS 6.7 的服务器。我需要在 Windows Small Business Server 2003 上连接到 MS SQL Server 2005。在 CentOS 中,我安装了 FreeTDS,并设法使用以下命令从终端连接到 SQL Server:

# TDSVER=7.0 tsql -H ServerIPAdress -p 1433 -U username -P password

据我所知, 中的此命令绕过设置freetds.conf .
现在我需要从 PHP 脚本连接。我正在使用 PDO 扩展,我尝试了这个 DSN 字符串:
$db = new PDO("dblib:version=7.0;host=ServerIPAdress;dbname=Database;","username","password");

这导致我出现第一个错误:

Could not find driver



好的,我明白了 - 我的 PHP 5.3.3 安装没有安装 PDO 驱动程序 数据库库 .
我的问题:如何在 CentOS 中安装 pdo_dblib 驱动程序?许多教程和答案建议通过此命令安装:
yum install php5-sybase

但是那个包不存在:

No package php-sybase available.



如果我用命令检查 tsql 配置
tsql -C

我得到这些输出:
                       Version: freetds v0.95
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: yes

据我了解,我需要配置 FreeTDS:
./configure --enable-msdblib --with-pdo-dblib=/usr/local

但是安装后如何配置 FreeTDS?我试图删除当前版本,但我找不到这样做的方法。我也尝试安装另一个版本,但配置没有改变。

任何建议表示赞赏。

最佳答案

当我运行命令 # odbcinst -j我可以看到这个输出:

unixODBC 2.3.0
DRIVERS ...........: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLSETPOSIROW Size.: 8

我的内容 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 = 7.0

# 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 = 7.0

# A typical Microsoft server
[MSServer]
host = 192.168.1.55
port = 1433
tds version = 7.0

odbcinst.ini :
[FreeTDS]
Description = FreeTDS v7.0
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1

odbc.ini :
[MSSQL]
Driver = FreeTDS
Description = MSSQL Server Connection
TDS_Version = 7.0
Trace = No
Server = MSServer
Port = 1433
Database = MyDatabase
Username = DOMAIN\MyUsername
Password = MyPassword

我可以联系 isql 当我指定用户名和密码时的命令:
# isql -v MSSQL "DOMAIN\MyUsername" MyPassword

但如果我省略用户名和密码 isql 生成错误:
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed

我怀疑我的用户名有问题,因为当我连接到 SQL Server 2005 时,我必须在用户名之前使用域名后跟反斜杠。

更新:
我成功地在 PHP 中建立了连接,现在我可以运行查询了。我在脚本顶部添加了这一行: putenv("FREETDSCONF=/usr/local/etc/freetds.conf")为什么这是必要的?

关于tsql - CentOS 6.7 和 Windows MSSQL 连接 - FreeTDS 和 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809963/

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