SQLite Display table content

I’ve established a connection to the database in the config.php file, however, I get an error when I run a code to display what’s in a table. This is what I get PDOException thrown with message "SQLSTATE[HY000] [2002] No such file or directory" and the highlighted row is $this->connection = new PDO($this->dsn, $options['user'], $options['password']);

I know SQLite doesn’t require a username and password. I don’t know where to go from here. What do I do next?

Are you sure the path to the database is correct?

i do it like this which is relative to the config.php file


  'db' => [
        'type'     => 'sqlite',
        'database' => __DIR__ . '/../db/yourdb.sqlite'
  ],

My database is in site/db/

Thank you for your reply.

My config.php file has:

'db' => [
        'type'     => 'sqlite',
        'database' => '/db/budget.db'
    ]

My database is in a folder named “db” and the folder sits in the root alongside index.php

Ok try

 'db' => [
        'type'     => 'sqlite',
        'database' => __DIR__ . '/../../db/budget.db'
  ],

You just need to go up another level

It worked. Perfect.

Thanks. You’re awesome.

1 Like