Yii v2 snippet guide III

Comparing #97 with #98

Revision #98 was created by rackycz rackycz on Aug 14, 2022, 7:42:22 PM.

Microsoft Access MDB

Content

[...]
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.