简体   繁体   中英

connecting to MS access with php when defined password for database

I am trying to connect Ms Access DataBase from php . My codes like this in config.php

 define('DBNAMEACCESS',  '\\'."\\xxx.xxx.xxx.xxx\\test\\test.accdb");
        define('DBACCESSPASSWORD', 'mypassword');
        define('DBACCESSUSERNAME', '');

and in process.php like this:

     include './config.php';
   if (!file_exists(DBNAMEACCESS)) {
            die("Could not find database file.");
        }
 try{
            $dbName=DBNAMEACCESS;
            $username=DBACCESSUSERNAME;
            $password=DBACCESSPASSWORD;
             $dba = odbc_connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbName",$username, $password);

   if ($dba) {
/*......*/
} else
            {
                die("Could not connect to access database");
            }
             }
        catch (Exception $ex) {
//            var_export($ex);
                setmessage($ex) ;
        }

when the password is defined for access file , I get this error on this line: My error: odbc_connect(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'. It may not be a database that your application recognizes, or the file may be corrupt., SQL state S1000 in SQLConnect in this line

         $dba = odbc_connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbName",$username, $password);

and when the password is not defined for access file,My codes execute correctly.

The problem was related to the Microsoft Access Database Engine Installation. I've tried with this and restart my computer. then worked correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM