我需要帮助修复错误:SQL state IM014 in SQLConnect
和SQL state IM002 in SQLConnect
。找不到数据源名称,也没有指定默认驱动程序
我运行相同的脚本,一个在webserver/remote/
上,另一个从本地机器尝试访问同一个数据库,但我得到了不同的错误信息。
当我从网络服务器上运行它,我得到
SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQL
哪里,当我在本地机器上运行它,我得到
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
我用PHP脚本下面的代码连接到本地数据库
$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.in我看起来像下面
[ODBC 32 bit Data Sources]
manager=Sage Line 50 v16 (32 bit)
t=SQL Server Native Client 10.0 (32 bit)
s1=Pervasive ODBC Client Interface (32 bit)
SageLine50v19=Pervasive ODBC Client Interface (32 bit)
[manager]
Driver32=C:\Windows\SysWOW64\S16DBC32.dll
[t]
Driver32=C:\Windows\system32\sqlncli10.dll
[s1]
Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll
[SageLine50v19]
Driver32=C:\Program Files (x86)\Pervasive Software\PSQL\bin\w3odbcci.dll
DSN体系结构不匹配是因为应用程序的位数和驱动程序的位数不同,所以您试图在64位应用程序中使用32位驱动程序,反之亦然。你需要匹配它们才能正常工作。在您的本地机器上,如果您正在使用32位驱动程序切换到64位驱动器并重试。在服务器上,您是否安装了驱动程序和DSN? – KylePorter 2014-10-16 16:40:28
@KylePorter谢谢你的回复我不知道DSN,但我知道我的网络主机添加了“odbc”扩展名。我将向他们询问有关DSN的信息 – Keven 2014-10-16 17:32:54
仅安装ODBC驱动程序是不够的,您还必须在服务器上创建一个要连接的DSN,与本地计算机上的相同。如果您正在部署相同的代码,那么您必须确保DSN的设置与本地的相同。 – KylePorter 2014-10-17 18:01:58