Revision #98 has been created by rackycz on Aug 14, 2022, 7:42:22 PM with the memo:
Microsoft Access MDB
« previous (#97) next (#99) »
Changes
Title
unchanged
Yii v2 snippet guide III
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
tutorial,yii2,beginer
Content
changed
[...]
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',
//'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
othercorrect bit-version. You must uninstall MS Access in that case.