php无法连接到sql server 2008(使用pdo dblib)

我有一个SQL Server 2008 R2(在Windows Server 2008 64bit上运行),我正在尝试连接 PHP </ p>

我的PHP服务器配置:</ p>

CentOS 6.6 </ p>

PHP 5.5.24(已编译 - with -mssql = / usr / local / freetds --with-pdo-dblib = / usr / local / freetds)</ p>

Apache 2.4.12 </ p>

SELinux被禁用(根据此解决方案: PDO DBLIB访问SQL Server 2008和 2012 )</ p>

我编写了以下PHP代码以连接到SQL服务器:</ p>

  try {
require“ classes / mypdo.class.php“;
$ pdo = new MyPDO('dblib:dbname = myDB; host = myServer','myUser','myPassword');
$ pdo-&gt; debug = true; \ n} catch(PDOException $ e){
die(“连接失败:{$ e-&gt; getMessage()}”);
}
</ code> </ pre>

连接失败并显示错误:</ p>

 连接失败:SQLSTATE [HY000]未知h  ost机器名称(严重性2)
</ code> </ pre>

我尝试了其他DSN语法,如:</ p>

  $ pdo = new MyPDO  ('dblib:host = 192.168.0.10','myUser','myPassword'); 
$ pdo = new MyPDO('dblib:host = 192.168.0.10:1433','myUser','myPassword'); \ n $ pdo = new MyPDO('dblib:host = myServer','myUser','myPassword');
</ code> </ pre>

以及许多其他变体...
当 我使用IP地址而不是DSN,错误是:</ p>

 连接失败:SQLSTATE [HY000]无法连接:Adaptive Server不可用或不存在(严重级9)\  n </ code> </ pre> 

/etc/freetds.conf </ p>

  [global] 
tds version = 7.1
dump file = / tmp /freetds.log
timeout = 10
connect timeout = 10
text size = 64512
client charset = UTF-8

[myServer]
host = 192.168.0.10
port = 1433
tds version = 7.1
< / code> </ pre>

我怀疑PHP忽略了freetds.conf(无法确认)。</ p>

当我使用tsql时,连接正常。 </ p>

  tsql -S myServer -U MyUser -P MyPas  sword 
locale是“en_US.UTF-8”
locale charset是“UTF-8”
使用默认字符集“UTF-8”
1&gt;

</ code> </ pre>

PHP拒绝连接SQL服务器的原因是什么?</ p>
</ div>

展开原文

原文

I have a SQL server 2008 R2 (running on Windows server 2008 64bit), which I'm trying to connect from PHP

My PHP server configuration:

CentOS 6.6

PHP 5.5.24 (compiled --with-mssql=/usr/local/freetds --with-pdo-dblib=/usr/local/freetds)

Apache 2.4.12

SELinux is disabled (according to this solution: PDO DBLIB accessing SQL Server 2008 and 2012)

I wrote the following PHP code to connect to the SQL server:

try {
    require "classes/mypdo.class.php";
    $pdo = new MyPDO('dblib:dbname=myDB;host=myServer', 'myUser', 'myPassword');
    $pdo->debug = true;
} catch (PDOException $e) {
    die("Connection failed: {$e->getMessage()}");
}

The connection failed with an error:

Connection failed: SQLSTATE[HY000] Unknown host machine name (severity 2)

I tried other DSN syntaxes like:

$pdo = new MyPDO('dblib:host=192.168.0.10', 'myUser', 'myPassword');
$pdo = new MyPDO('dblib:host=192.168.0.10:1433', 'myUser', 'myPassword');
$pdo = new MyPDO('dblib:host=myServer', 'myUser', 'myPassword');

and many other variations... When I use an IP address instead of DSN the error is:

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

/etc/freetds.conf

[global]
tds version = 7.1
dump file = /tmp/freetds.log
timeout = 10
connect timeout = 10
text size = 64512
client charset = UTF-8

[myServer]
host = 192.168.0.10
port = 1433
tds version = 7.1

I suspect that PHP ignoring freetds.conf (can't confirm it).

When I use tsql the connection is working.

tsql -S myServer -U MyUser -P MyPassword
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 

What is the reason that PHP refusing to connect to the SQL server?

1个回答



php.ini </ strong> </ strong> </ p>

请尝试更改:</ p>

  mssql.secure_connection = Off 
</ code> </ pre>

</ p>
\ n

  mssql.secure_connection = On 
</ code> </ pre>
</ div>

展开原文

原文

There are sometimes problems with an setting inside php.ini

Please try to change:

mssql.secure_connection = Off

to

mssql.secure_connection = On

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐