我正在尝试将托管 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
最佳答案
Error connecting to the ODBC database: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
问题:
这是您的数据源名称:
[ODBC 32 bit Data Sources]
但是在你的 php 中你放了
$odbc['dsn'] = "SageLine50v19";
解决方案:
决定你改变哪一个:
odbc.ini
[SageLine50v19]
或php
$odbc['dsn'] = "ODBC 32 bit Data Sources";
关于php - 尝试将托管 Web 应用程序连接到本地数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26304207/