【发布时间】: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