尝试将托管的Web应用程序连接到本地数据库?
问题描述:
我正尝试将托管的网站应用程序连接到本地数据库。首先,我是越来越Fatal error: Call to undefined function odbc_connect()
错误,但添加了“ODBC”扩展我开始尝试将托管的Web应用程序连接到本地数据库?
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
答
错误连接到ODBC数据库:[的unixODBC] [驱动程序管理器]数据 源找不到名称,并没有指定默认驱动程序
问题:
这是您的数据源名称:
[ODBC 32 bit Data Sources]
但是在你的php中你把
$odbc['dsn'] = "SageLine50v19";
解决方案:
决定至极一个你改变:
ODBC.INI
[SageLine50v19]
或PHP
$odbc['dsn'] = "ODBC 32 bit Data Sources";
答
这究竟是什么平台?
鉴于unixODBC我期望Unix/Linux。但是.dll的驱动程序指示Windows。哪一个?
如果驱动程序管理器试图加载一个库并失败,它会给出“数据源名称未找到,并且没有指定默认驱动程序”(这是规范坚持它的作用),如果您尝试使用Windows Unix上的驱动程序,那么我预计它会加载失败。
非常感谢@meda!你是正确的,但这里是我想要完成的PHP代码是在我的网络服务器上,我试图访问我的本地MySQL数据库。我该如何解决这个问题。你认为这是可能的还是有什么办法可以做到这一点? – Kin 2014-10-11 05:38:38
是的,当然是添加另一个许多条目的odbc只是创建一个[localshostdsn]然后指向它localhost – meda 2014-10-11 15:56:46
谢谢!我做了,现在odbc.ini看起来像这样[ODBC 32位数据源] t = SQL Server Native Client 10.0(32位) SageLine50v19 =普适ODBC客户端接口(32位) ODBC 32位数据源=普适ODBC客户端接口(32位) Driver32 = C:\ Program Files(x86)\ Pervasive Software \ PSQL \ bin \ w3odbcci。dll的 localshostdsn =普适ODBC客户端接口(32位) [T] Driver32 = C:\ Windows \ System32下\ sqlncli10.dll [SageLine50v19] Driver32 = C:\程序文件(x86)\普适SOFTWARE \ PSQL \ bin \ w3odbcci.dll [localshostdsn] Driver32 = C:\ Program Files(x86)\ Pervasive Software \ PSQL \ bin \ w3odbcci.dll' – Kin 2014-10-11 20:08:46