Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite3 / PDO - No such table though it does exist

Tags:

php

sqlite

pdo

I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.

This line of PHP causes the PDOException:

$query = "SELECT * FROM users";
$results = self::$app->db->query($query);

And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.

I don't really know what to do as I am new to Slim as well as SQLite.

Thank you for your help :-)

like image 369
Jeahel Avatar asked Oct 15 '14 09:10

Jeahel


2 Answers

The database that you have opened does not contain this table.

SQLite will happily open any file name; if it does not exist, it will create a new, empty database.

Check your database file name.

like image 153
CL. Avatar answered Nov 12 '22 07:11

CL.


Thanks to the accepted answer that pointed me in the right direction. I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :

# file: PROJECT_ROOT/.env
DATABASE_URL="sqlite:///../my_super.db"

But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:

PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql

like image 31
gogaz Avatar answered Nov 12 '22 07:11

gogaz