2014-01-21 18 views
0
$dbName = "C:\path\folder"; 
$user=""; $password=""; 

if(!file_exists($dbName)) { 
    die("Could not find database file."); 
} echo"connecting..."; 

$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; 
DBQ=$dbName; $user, $password"); 

以上是我的連接字符串代碼爲.mdb,我在win7上運行IIS7。我的PHP頁面運行完美,但是當我包括或將連接字符串上面我的網頁,它只是加載,直到PHP和MS訪問不工作

echo"connecting..."; 

和字符串下不加載任何東西......

$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$dbName; $user, $password"); 

所以我轉移$db = new PDO()...在頁腳區域,一切都加載在這個字符串之上。

任何人都可以幫助我解決這個瘋狂的問題嗎?

回答

0

Manual,連接字符串應該是

$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", $user, $password); 

在你的情況下,它應該是

$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; 
Dbq=$dbName" $user, $password); 
+0

感謝您的回覆,但我已經嘗試過了。^_ ^ – yul757

0

其實,我現在都沒有了。

$conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=Northwind.mdb','',''); 

if($conn){ 
    echo "Database Connected!"; 
} else echo "Database Disconnected."; 

希望這可以幫助那些剛接觸php和MS Access的人。

謝謝。