Difference between #96 and #97 of
Yii v2 snippet guide III

Revision #97 has been created by rackycz on Aug 14, 2022, 7:40:36 PM with the memo:

Microsoft Access MDB
« previous (#96) next (#98) »

Changes

Title unchanged

Yii v2 snippet guide III

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,yii2,beginer

Content changed

[...]
If you want to see the code coverage, do what is described in the documentation (link above). Plus make sure that your PHP contains [xDebug](https://gist.github.com/odan/1abe76d373a9cbb15bed)! And mind the difference in settings of xDebug2 and xDebug3! If xDebug is missing, you will receive error "No code coverage driver available".

**Microsoft Access MDB**
---
Under Linux I haven
't suceeded, but when I install a web server on Windows (for example XAMPP Server) I am able to install "Microsoft Access Database Engine 2016 Redistributable" and use *.mdb file. So first of all you should install the web server with PHP and you should know wheather you are installing 64 or 32bit versions. Probably 64. Then go to page [Microsoft Access Database Engine 2016 Redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=54920) (or find newer is available) and install correspoingnding package (32 vs 64bit) Then you will be able to use following DSN string in DB connection:
 
 
```
. (The code belongs to file config/db.php):
 
 
```
 
<?php
 
$file = "C:\\xampp\\htdocs\\khc\\Database1.mdb"; // ...return [
 
    'class' => 'yii\db\Connection',
'dsn' => "odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$file;Uid=;Pwd=;",     'username' => '',     'password' => '',     'charset' => 'utf8', // And'schemaMap' => [
 
    //  'odbc'=> [
 
    //    'class'=>'yii\db\pgsql\Schema',
 
    //    'defaultSchema' => 'public' //specify your schema here
 
    //  ]
 
    //], 
 
 
    // Schema cache options (for production environment)
 
    //'enableSchemaCache' => true,
 
    //'schemaCacheDuration' => 60,
 
    //'schemaCache' => 'cache',
 
];
 
```
 
 
Then
use this to query a table: ```
 
$data = Yii::$app->db->createCommand("SELECT * FROM TableX")->queryAll(); var_dump($data); ```
 
Note: If you already have MS Access installed in different bit-version then your PHP, you will not be able to install the engine in the other bit-version. You must uninstall MS Access in that case.
 
8 0
4 followers
Viewed: 136 979 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Jan 21, 2021
Last updated: 8 months ago
Update Article

Revisions

View all history