3

I'm trying to play with Symfony4 and SQlite3. After:

composer create-project symfony/website-skeleton my-project

and something like LuckyNumber, I try to define DB-connection. in: config/packages/doctrine.yaml is:

doctrine:
    dbal:
        # configure these for your database server
        url: '%env(DATABASE_URL)%'

and in .env :

DATABASE_URL="sqlite:///%kernel.project_dir%/db/sqlite3.db3"

Is there any console-command to test connection? Or maybe:

php bin/console doctrine:query:sql "select * from all_files"

should return resource or something else way to simply test the connection? Unfortunatelly Google is silent like a grave :-( How do you test DB connections in Symfony4/Doctrine?

after: php bin/console doctrine:query:sql "select * from all_files"

I got: In AbstractSQLiteDriver.php line 89: An exception occurred in driver: could not find driver
In PDOConnection.php line 47: could not find driver

php7.2-sqlite3-dbgsym is installed and apache2 restarted (but I guess Symfony console do nto use Apache?)...

edit:

after Mike`s prompt, (there wasn't pdo_sqlite for this php ver.) I get:

~/Dokumenty/projects/symfony_mdb/my-project$ php bin/console doctrine:query:sql "select * from all_files"

In AbstractSQLiteDriver.php line 86:
An exception occurred in driver: SQLSTATE[HY000] [14] unable to open database file  
In PDOConnection.php line 47:
  SQLSTATE[HY000] [14] unable to open database file  

but this is new file and none of process using it (I guess). It is possible to open it with SQlite GUI and run query with expected answer...

  • 1
    What does `php -m | grep pdo` say? – Mike Doe Feb 20 '18 at 21:22
  • `php -m | grep pdo` `pdo_mysql` ...no pdp_sqlite ...? why!? –  Feb 20 '18 at 21:23
  • thank you, ok, I had installed sqlite for php7.2 but using php7.1, now is ok, after php -m | grep pdo I get pdo_sqlite too. Thank you. Now I get `SQLSTATE[HY000] [14] unable to open database file` ... –  Feb 20 '18 at 21:33
  • The file and the directory where the file is located both have to be writable by the process. Keep in mind you will only be able to have one instance of your app running as simultaneous access by multiple processes to a SQLite database is not possible. This matters if you plan to execute lots of from jobs for instance. – Mike Doe Feb 20 '18 at 21:38
  • *cron jobs. I cannot edit my post anymore lol this is madness. – Mike Doe Feb 20 '18 at 21:44
  • This is new one copy of file with 777 permissions (folder 777 too ), I have none CRON process conected with this (new) file, and I am able to open it with f.ex. SQLiteBrowser and above query give expected answer... –  Feb 20 '18 at 22:02

1 Answers1

1

Yes! I got it!

the problem was in:

config/packages/doctrine.yaml

wrong:

url: '%env(DATABASE_URL)%'

but sholud be:

url: '%env(resolve:DATABASE_URL)%'

Thank you for help!

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
  • Great, please mark you answer as the solution as well. – Mike Doe Feb 21 '18 at 08:23
  • :-) I agree with you, find solution for own question - its funnily. First of all your prompt was very helpful for my Mike, and next I had problem with .env conf, so I tried to fix it and hapilly found answer. Thank you for help Mike! I was almost sure about pdo_sqlite instalation. –  Feb 21 '18 at 10:12