【问题标题】:try to connect hosted web application to local database?尝试将托管的 Web 应用程序连接到本地数据库?
【发布时间】:2014-10-10 16:44:33
【问题描述】:

我正在尝试将托管的 Web 应用程序连接到本地数据库。首先我收到Fatal error: Call to undefined function odbc_connect() 错误,但添加“odbc”扩展后我开始收到

Error connecting to the ODBC database: [unixODBC][Driver Manager]Data source name not found, and no default driver specified

我在 php 脚本中使用以下代码通过 ODBC 连接到本地数据库

$odbc['dsn'] = "SageLine50v19";
$odbc['user'] = "Peac";
$odbc['pass'] = "XXXX";
$mysql['host'] = "localhost";
$mysql['user'] = "root";
$mysql['pass'] = "";
$mysql['dbname'] = "sagetest";
$mysql['idfield'] = "id";


// Step 1: Connect to the source ODBC database
if ($debug) echo "Connect to " . $odbc['dsn'] . ' as ' . $odbc['user'] . "\n";
$conn = odbc_connect($odbc['dsn'], $odbc['user'], $odbc['pass']);
if (!$conn) {
die("Error connecting to the ODBC database: " . odbc_errormsg());
}

// loop through each table 
$allTables = odbc_tables($conn);
$tablesArray = array();
while (odbc_fetch_row($allTables)) {
 if (odbc_result($allTables, "TABLE_TYPE") == "TABLE") {
    $tablesArray[] = odbc_result($allTables, "TABLE_NAME");
 }
}
 //print_r($tablesArray);      // to list all tables

我的 ODBC.ini 如下所示

[ODBC 32 bit Data Sources]
t=SQL Server Native Client 10.0 (32 bit)
SageLine50v19=Pervasive ODBC Client Interface (32 bit)

[t]
Driver32=C:\Windows\system32\sqlncli10.dll
[SageLine50v19]
Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll

【问题讨论】:

    标签: php mysql web-applications odbc database-connection


    【解决方案1】:

    连接到 ODBC 数据库时出错:[unixODBC][Driver Manager]Data 源 找不到名称,并且没有指定默认驱动程序

    问题:

    这是您的数据源名称:

    [ODBC 32 bit Data Sources]
    

    但是在你的php中你放了

    $odbc['dsn'] = "SageLine50v19";
    

    解决方案:

    决定你改变哪一个:

    odbc.ini

    [SageLine50v19]
    

    或php

    $odbc['dsn'] = "ODBC 32 bit Data Sources";
    

    【讨论】:

    • 非常感谢@meda!你是对的,但这是我想要完成的 php 代码在我的网络服务器上,我正在尝试访问我本地的 mysql 数据库。我该如何解决这个问题。你认为这是可能的还是有什么方法可以做到这一点?
    • 是的,当然添加另一个尽可能多的条目到 odbc 只需再创建一个 [localshostdsn] 然后将其指向 localhost
    • 谢谢!!我做到了,现在 odbc.ini 看起来像这样[ODBC 32 bit Data Sources] t=SQL Server Native Client 10.0 (32 bit) SageLine50v19=Pervasive ODBC Client Interface (32 bit) ODBC 32 bit Data Sources=Pervasive ODBC Client Interface (32 bit) Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll localshostdsn=Pervasive ODBC Client Interface (32 bit) [t] Driver32=C:\Windows\system32\sqlncli10.dll [SageLine50v19] Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll [localshostdsn] Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll
    • 并非如此添加localshostdsn后。我把odbc.ini的内容放在前面的评论上。我用$odbc['dsn'] = "ODBC 32 bit Data Sources";
    • 哦等等你说代码在服务器上,那么你怎么能从那里访问你的本地数据库。这是不可能的
    【解决方案2】:

    这是在哪个平台上?

    鉴于 unixODBC,我希望是 Unix/Linux。但是 .dll 的驱动程序表示 Windows。是哪一个?

    如果驱动程序管理器尝试加载 lib 并失败,如果您尝试使用 Windows 驱动程序,它将给出“未找到数据源名称,并且未指定默认驱动程序”(规范坚持这样做)在 Unix 上,那么我希望它无法加载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      相关资源
      最近更新 更多