2014-10-10 148 views
1

我正嘗試將託管的網站應用程序連接到本地數據庫。首先,我是越來越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 

回答

0

錯誤連接到ODBC數據庫:[的unixODBC] [驅動程序管理器]數據 源找不到名稱,並沒有指定默認驅動程序

問題:

這是您的數據源名稱:

[ODBC 32 bit Data Sources] 

但是在你的php中你把

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

解決方案:

決定至極一個你改變:

ODBC.INI

[SageLine50v19] 

PHP

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

非常感謝@meda!你是正確的,但這裏是我想要完成的PHP代碼是在我的網絡服務器上,我試圖訪問我的本地MySQL數據庫。我該如何解決這個問題。你認爲這是可能的還是有什麼辦法可以做到這一點? – Kin 2014-10-11 05:38:38

+0

是的,當然是添加另一個許多條目的odbc只是創建一個[localshostdsn]然後指向它localhost – meda 2014-10-11 15:56:46

+0

謝謝!我做了,現在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

0

這究竟是什麼平臺?

鑑於unixODBC我期望Unix/Linux。但是.dll的驅動程序指示Windows。哪一個?

如果驅動程序管理器試圖加載一個庫並失敗,它會給出「數據源名稱未找到,並且沒有指定默認驅動程序」(這是規範堅持它的作用),如果您嘗試使用Windows Unix上的驅動程序,那麼我預計它會加載失敗。

相關問題