使用PHP(使用dblib驱动程序),我试图连接到具有IPv6地址的MSSQL服务器。代码看起来像这样:
<?php
$db_host = 'ff3e:30:fd66:98:5837::';
$db_port = '1433';
$db_name = 'thedb';
$db_user = 'theuser';
$db_pass = 'thepass';
$conn = new PDO("dblib:host=$db_host:$db_port;dbname=$db_name", $db_user, $db_pass);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$conn = null;
使用php check.php
运行此操作会返回[ERR] SQLSTATE[HY000] Unknown host machine name (severity 2)
,即使主机和端口100%正确并且没有防火墙问题,因为我可以轻松地nmap
它:
$ nmap -6 -Pn -p 1433 ff3e:30:fd66:98:5837::
Starting Nmap 6.00 ( http://nmap.org ) at 2016-02-05 16:50 CET
Nmap scan report for <hostname> (ff3e:30:fd66:98:5837::)
Host is up (0.0019s latency).
PORT STATE SERVICE
1433/tcp open ms-sql-s
为什么这不起作用?这是IPv6问题吗?
如果有用,执行PDO::getAvailableDrivers()
会导致
Array
(
[0] => dblib
[1] => mysql
)