【问题标题】:Using a FreeTDS ODBC driver to connect Linux PHP to a SQL Server使用 FreeTDS ODBC 驱动程序将 Linux PHP 连接到 SQL Server
【发布时间】:2010-12-14 17:00:46
【问题描述】:

我刚刚使用一个新的虚拟帐户设置了我的 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);

【问题讨论】:

    标签: php sql sql-server odbc


    【解决方案1】:

    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);

    【讨论】:

    • SQL Server Native Client 是 Windows 独有的。作者在标题上明确说明了他正在使用的 SO。
    • 此解决方案不适用于 Linux
    猜你喜欢
    • 2020-06-01
    • 2019-12-12
    • 2017-01-17
    • 2019-02-09
    • 2018-10-04
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多