4

i want to read data of an MDB access file with my laravel project. I'm trying with a local file but i got this errors:

Could not find database file.

The code of my test is:

$dbName = $_SERVER["DOCUMENT_ROOT"] . "C:\Temp\test.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid='Admin'; Pwd=;");

And

try
{
    $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Temp\test.mdb; Uid=; Pwd=;");
}
catch(PDOException $error_mess)
{
    echo $error_mess->getMessage();
}

With error:

SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][Driver Manager ODBC] Nome origine dati non trovato e driver predefinito non specificato.

I managed to get the two databases to communicate starting from the access file and following this guide :Exporting Access Data to MySQL.

I don't want to use this method. What I would like to read is the db access from laravel. It's possible? Can you help me?

Here some screenshot of my phpinfo and ODBC Drivers:

phpinfo drivers

ODBC x64 ODBC x86

Probably is the drivers, someone can help me?

I solved and entered the PDO connection in the database file like this:

'access' => [
            'driver' => 'odbc',
            'dsn' => 'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\Temp\test.mdb;',
            'database' => 'test.mdb',
            'username' => '',
            'password' => ''
        ]
Roberto
  • 51
  • 1
  • 4
  • 3
    Does this answer your question? [Why am I getting "Data source name not found and no default driver specified" and how do I fix it?](https://stackoverflow.com/questions/58571740/why-am-i-getting-data-source-name-not-found-and-no-default-driver-specified-an) – Erik A Nov 15 '19 at 09:53
  • I tried, but it doesn't work. – Roberto Nov 15 '19 at 11:49
  • you tried what? As described in the duplicate, this is an issue with the presence of database drivers, and it depends if you're running 32-bits or 64-bits PHP. If you've read the duplicate, installed the proper database driver and verified it's the right bitness, and still encounter this error, please edit the question (preferably with `phpinfo()` output and a screenshot of the database drivers you have installed) so we can try to reproduce the issue. – Erik A Nov 15 '19 at 12:03
  • I've installed the proper database driver, but i have the same error. What can i do now? – Roberto Nov 18 '19 at 13:25
  • 1
    As evident by your screenshots, the `{Microsoft Access Driver (*.mdb)}` driver is only installed for 32-bit, while PHP is running in 64-bit mode. Use the driver you've got installed for 64-bit (the `{Microsoft Access Driver (*.mdb, *.accdb)}` one). – Erik A Nov 18 '19 at 13:28
  • 1
    Also note: it looks like you've installed two different versions of Access, as can be seen by the drivers you use (the 32-bit version is 16.00, the 64-bit version is 14.00). That's not supported and can lead to trouble. If you still have issues after switching the driver name, I recommend a full uninstall + reinstall of Access, and only installing the 64-bit version. – Erik A Nov 18 '19 at 13:31
  • Ok now i obtain a blank page with the execution of my second code(i don't know if it worked) but the same error with the execution of first. Do you suggest to reinstall access? Or do another test? Sorry but is my first time. – Roberto Nov 18 '19 at 15:20
  • Seems to me your second code should return a blank screen if it succeeds, since it outputs nothing at all in that case, and an error if it fails. So I'd start by actually testing if you have a valid connection. – Erik A Nov 18 '19 at 15:44
  • 1
    Also, note your first case will always fail because it will always produce an invalid path. You can easily check this by echoing the path. – Erik A Nov 18 '19 at 15:45
  • How can I do to insert this connection in the database.php in order to recall it in the project? – Roberto Nov 19 '19 at 08:04
  • Please first consult the manual and make an attempt. Just google PDO insert – Erik A Nov 19 '19 at 08:08
  • Thanks for your support @ErikA – Roberto Nov 21 '19 at 14:19
  • Hi @Roberto, I have an error, "Unsupported driver [odbc]", do you have that error? – Nicolas400 Jan 05 '21 at 19:35

0 Answers0