php pdo连接到mssql实例 [英] php pdo connection to mssql instance

查看:133
本文介绍了php pdo连接到mssql实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了从PHP连接到MSSQL数据库的问题.

I'm running into a problem connecting to a MSSQL database from PHP.

我们在同一台linux服务器上有2个应用程序.

We've got 2 applications on the same linux-server.

  • 应用程序A连接到简单" MSSQL服务器+数据库,并且没有问题.
  • 应用B连接到MSSQL服务器+ INSTANCE +数据库,但连接失败.

唯一的区别在于数据库位于MSSQL服务器的实例"中.

The fact that the database is within an "instance" of the MSSQL server seems to be the only difference.

该文档似乎并未指定如何在实例内连接数据库.

The documentation appears not to specify how to connect to a database within an instance.

示例(伪)代码:

<?php
$host="10.0.0.12";
$instance="specific"
$database="my-database"
$username="username";
$password="password";

$pdo = new PDO("dblib:host=${host}\\${instance};database=${database}", $username, $password);

大多数情况下,这都无法通过一条非常无意义的消息进行连接,例如:

This fails to connect, most of the time with a very uninformative message like:

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

我已经尝试了许多不同的DSN,以查看可能的效果,但似乎没有效果.

I've tried numerous different DSN's to see what might work, but none seem to work.

我可以使用什么DSN来使它正常工作?

What DSN might I use to get this working?

也欢迎从PHP连接到该数据库的替代方法作为建议.

Alternative ways to connect from PHP to this database are also welcome as suggestions.

推荐答案

每个MSSQL服务器实例都在其自己的端口号上运行. 您可以将MSSQL Server实例配置为使用固定端口号,而不使用动态端口号(这是默认端口号).

Every MSSQL server instance runs on its own port number. You can configure the MSSQL Server instance to use a fixed port number instead of a dynamic one (which is the default).

配置了固定端口后,您只需使用PDO连接到该端口号即可.不再需要在dsn或任何其他设置中引用该实例.

Once you've configure a fixed port, you can simply connect to that port number using PDO. There is no further need to reference the instance in the dsn or any other setting.

这篇关于php pdo连接到mssql实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆