0
votes

I'm using OctoberCMS and, using the DB settings in the .env file I can connect to the DB without issue and I see a database named "mydatabase". BUT when I do php artisan tinker and do DB::connection()->getPdo(); I get the following:

InvalidArgumentException with message 'Database (mydatabase) does not exist.'

When I do echo env('DB_HOST'); and echo env('DB_PORT'); etc (for DB_DATABASE, DB_USERNAME and DB_PASSWORD) everything looks good. I can connect with those parameters with the mysql CLI command. And yet DB::connection()->getPdo(); is failing.

Any ideas?

I'm running OctoberCMS 1.0.443. tail -f /path/to/myproject/storage/logs/system.log doesn't return anything (despite being writable)

2
The error is saying that the database called mydatabase doesnt exist. It's not saying the connection settings are wrong so DB_HOST and DB_PORT are not where the problem is. If you run a CREATE SCHEMA mydatabase; would it work? - apokryfos
@apokryfos - the DB exists. SELECT SUM(TABLE_ROWS) FROM Information_schema.tables WHERE table_schema = 'mydatabase'; says there are ~1,300 rows. My company has a working OctoberCMS install on a prod server - I'm trying to connect to a local install of OctoberCMS that connects to the prod DB. I can connect to it fine using the mysql CLI client (as the SQL query I just provided demonstrates) - I just can't seem to connect using DB::connection()->getPdo()... - neubert

2 Answers

1
votes

Are you sure you're using the .env file correctly? If you don't have calls to env() in your config/database.php file, then it won't be used. October does not use a .env file by default, you would either have had to add those calls yourself to the configuration files or you would have had to run php artisan october:env to do it automatically for you.

0
votes

Turns out I didn't have DB_DATABASE set in my .env. I had all the other DB_* values but not that one...