使用 FreeTDS ODBC 驱动程序将 Linux PHP 连接到 SQL Server

发布于 2024-10-07 17:43:19 字数 632 浏览 0 评论 0原文

我刚刚使用新的虚拟帐户设置了我的 freetds.conf 文件来连接到 SQL Server 数据库,但我不确定何时何地告诉我的 PHP 脚本要连接到哪个数据库,下面是我的设置

odbc.ini

[McDo]
ServerName = server1
Driver  = FreeTDS
Description = MyServer 
Trace   = Yes

freetds.conf

[server1]
host = 66.111.xxx.xxx
port = 1433
tds version = 7.0

和这是我的 PHP 连接脚本。现在确定我在哪里告诉脚本连接到哪个数据库。

putenv('ODBCINI=/etc/odbc.ini');

$connect = odbc_connect("server1", "username", "password");

//$query = "SELECT name_ID  FROM ext_name";

if(!$connect){
echo "not connected";

}else{
echo "connected";
}

odbc_close($connect);

I just set up my freetds.conf file with a new virtual account to connect to a SQL Server database but I am not sure when and where I tell my PHP script which database to connect to below are my settings

odbc.ini

[McDo]
ServerName = server1
Driver  = FreeTDS
Description = MyServer 
Trace   = Yes

freetds.conf

[server1]
host = 66.111.xxx.xxx
port = 1433
tds version = 7.0

And here is my PHP connect script. Now sure where I tell the script to connect to which database.

putenv('ODBCINI=/etc/odbc.ini');

$connect = odbc_connect("server1", "username", "password");

//$query = "SELECT name_ID  FROM ext_name";

if(!$connect){
echo "not connected";

}else{
echo "connected";
}

odbc_close($connect);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ人海孤独症 2024-10-14 17:43:19

php 手册显示:

// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

The php manual shows:

// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文