MSSQL VIA FreeTDS,ODBC和Cpanel未知主机名(严重性2) [英] MSSQL VIA FreeTDS, ODBC, and Cpanel Unknown host machine name (severity 2)
问题描述
我已经在运行Centos 6.5x64的Cpanel服务器上安装了FreeTDS 0.91,ODBC.一切似乎都运行良好,我可以使用以下方式连接到远程MSSQL 2012服务器:
I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
并成功执行数据库中的查询.
and succesfully execute queries in the database.
我还可以通过以下方式进行连接:
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
但是由于某些原因/usr/local/freetds/bin/tsql -LH server.ip.here
不返回任何信息或错误,当证明我可以使用上述其他方法进行连接时,这没有多大意义.
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
现在,当从计算机上的cpanel帐户运行测试脚本时,我得到:
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
这是测试脚本:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
第一个注释行是使用sqlserv的旧行,由于x64 OS,我发现从我所知的行中根本不起作用.我也尝试过在用户周围通过""
并通过以及没有任何标记.
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with ""
around user and pass as well as no marks at all.
php -m
确实显示PDO
和pdo-dblib
.
有什么好主意的地方吗?
Any ideas where I can look next?
更新:此问题已得到解决.我错过了freetds.conf
:
Update: This was fixed. I missed in freetds.conf
:
[global]
# TDS protocol version
tds version = 8.0
最初设置为4.5,而不是8.
It was originally set to 4.5 instead of 8.
推荐答案
您实际上根本不需要ODBC,因为您的连接脚本使用的是pdo_dblib而不是odbc.您可以只安装FreeTDS,然后通过rawopts中的编译时间标志启用pdo_dblib并通过EasyApache进行重建.当然,cPanel在此方面的细节有些不同.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
我只是为一个朋友做的,并决定将其记录下来,因为很难在cPanel上找到关于FreeTds和pdo_dblib的准确清晰的信息.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
指南在这里: cPanel上的FreeTDS和pDO_dblib
这篇关于MSSQL VIA FreeTDS,ODBC和Cpanel未知主机名(严重性2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!