V
V
Vitaly Liber2015-04-28 13:33:55
Yii
Vitaly Liber, 2015-04-28 13:33:55

How to connect sqLite to Yii2?

There was a problem connecting the sqLite database to Yii2.
I looked at the documentation, but there is no clear connection example.
If someone has already connected sqLite to Yii2, please share your experience.
I'm interested in what you write in connection configuration

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'sqlite:/config/db.sql',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
];

and the folder where you put the sqlite database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kaart27, 2015-04-28
@kaart27

$_fn=realpath(__DIR__."/../data")."/data.db";

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'sqlite:'.$_fn,
];

the database is located in <site_root>/data/data.db
works on both IIS and LAMP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question