开发者

Specify application name when connecting to MSSQL from PHP

How can I specify the application name when connecting to Microsoft Sql Server from PHP?

In .Net applications the connection string can specify "application name=XXXX" but I don't see a way to do that in PHP.

We use FreeTDS with mssql_connect.

I have different sources writing to the database and I want to distinguish t开发者_StackOverflow中文版he sources.

Any ideas are well appreciated.


As mentioned without knowing exactly what lib you are using it is a bit hard to answer. However:

Through the ADODB Connection you should be able to achieve using something like:

$db = new COM("ADODB.Connection");
$dsn = "Provider=SQLOLEDB;User ID=sa;Initial Catalog=catalog;Data Source=(local);Application Name=XXXX";

Or if you are using PECL PDO_DBLIB >= 0.9.0 it suggests that appname is configurable within the DSN string.

$dsn = "mssql:host=localhost;dbname=testdb;appname=XXXX";

http://www.php.net/manual/en/ref.pdo-dblib.connection.php

Hope that helps


We had the same issue, and found that php hardcodes the application name to PHP 5.

We contributed a patch to add the desired functionality:

Bug id: 60124

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜