PHP and MS Access

后端 未结 5 1331
旧巷少年郎
旧巷少年郎 2020-12-04 01:30

How can we connect a PHP script to MS Access (.mdb) file?

I tried by including following PHP code:

$db_path =          


        
5条回答
  •  再見小時候
    2020-12-04 01:54

    it looks like a problem with the path seperators. ISTR that you have to pass backslashes not forward slashes

    The following works for me - with an MDB file in the webroot called db4

        $defdir = str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]);
        $dbq    =    $defdir . "\\db4.mdb";
    if    (!file_exists($dbq)) { die("Database file $dbq does not exist"); }
    
        $dsn = "DRIVER=Microsoft Access Driver (*.mdb);UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL=MS Access;DriverId=25;DefaultDir=$defdir;DBQ=$dbq";
        $odbc_conn = odbc_connect($dsn,"","")
            or die("Could not connect to Access database $dsn");
    

提交回复
热议问题