[英]PDO Error “Adaptive Server is unavailable” when connecting to MS SQL Database
I'm trying to connect to a MSSQL database with odbc in php. 我正在尝试使用php中的odbc连接到MSSQL数据库。 My issue is similar to this issue , I can connect with tsql, but not with php.
我的问题与此问题相似,我可以与tsql连接,但不能与php连接。 The answer to the problem not work because I think I don't have SELinux installed (I don't know what it is, but pacman not found this package (or with a similar name) on my computer) I don't understand why it doesn't work, odbc is installed and detected by php
这个问题的答案不起作用,因为我认为我没有安装SELinux(我不知道它是什么,但是pacman在我的计算机上找不到该软件包(或类似名称)),我不明白为什么它不起作用,PHP安装并检测了odbc
print_r(PDO::getAvailableDrivers());
Array ( [0] => odbc )
I'm connecting by doing that: 我正在这样做:
$dsn = 'odbc:Driver=FreeTDS;Server=127.0.0.1;Port:1433;Database=[my base name]';
$pdo = new PDO($dsn, $user, $password);
My base is not in local, I use a ssh tunel because the base in accessible only at my school, and we need an ssh tunnel. 我的基地不在本地,我使用ssh隧道,因为该基地只能在我的学校访问,并且我们需要ssh隧道。 And it work, I can connect myself to the base with tsql.
而且它可以正常工作,我可以使用tsql将自己连接到基础。
When I was connecting PHP to our MS SQL server, I could never get a connection established using ODBC drivers. 当我将PHP连接到我们的MS SQL服务器时,我再也无法使用ODBC驱动程序建立连接。
Instead, I downloaded the official PHP > SQL SERVER drivers direct from Microsoft. 相反,我直接从Microsoft下载了官方的PHP> SQL SERVER驱动程序。 You can find them here .
您可以在这里找到它们。
Once installed, you must configure your php.ini
file to include the new drivers, restart your web server and then use the following to open a new connection: 安装后,必须配置
php.ini
文件以包括新驱动程序,重新启动Web服务器,然后使用以下命令打开新连接:
$conn = new PDO("sqlsrv:Server=SERVER_IP,1433;Database=DATABASE_TO_OPEN;");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.