I would like to test the SQL Builder library atk4/dsql with Symfony 5 and am trying to set up the database connection. I tried following these instructions in the official docs.
I do not have enough experience with Symfony to find out how to set up a global class so the Atk4 library can use the database connection details (I did enter the db details in the .env file).
I have code like this:
<?php
namespace App\Repository;
use Atk4\Dsql\Query;
class UserRepository
{
public function getUser($username) {
$query = new Query();
$query ->table('user')
->where('username', $username)
;
// Debug Output
// print_r($query); die;
return $query->getOne();
}
}
But when running this I only get "Call to a member function execute() on null".
I have checked this (fantastic) collection of explanations for PHP Errors, but could not find one for this problem. The closest I could find is "Fatal error: Call to a member function ... on a non-object or null". There it explains that this error could occur if - as in the example above - $query were not an object. But $query is definitely an object (I got double confirmation by using gettype($query)
).
Therefore I assume that it is my missing database connection definition.
How do I set up the database connection and make DSQL use it for every query in Symfony 5? Or am I possibly overlooking something else?