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