Can't call PDO MYSQL Slim Framework

if i have class in a subfolder under src folder and i want to make use of the mysql db connection which i setup in the dependencies.php via

$container['db'] = function ($c) {
$settings = $c->get('settings')['db'];
$pdo = new PDO("mysql:host=" . $settings['host'] . ";dbname=" . $settings['dbname'],
    $settings['user'], $settings['pass']);
return $pdo;

How do i have to call it ? If i cal it same way as in my routes.php i get

"Call to a member function query() on null" currently i call it like this

$result  = $this->db->query("CALL user_info.`sp_user_login`('user', '1234567890')");

1 answer

  • answered 2018-02-13 19:15 NoSoup4you

    Ok, i figured it out finally

    $app->get('/black/{ip}', function (Request $request, Response $response, array $args) {
    $ip = $args['ip'];
    $blackObj = new Security\BlackList($this->db);
    $Success = $blackObj->check_blacklist($ip);
    echo $Success;

    I had to create an instance of BlackList Class and pass $this->db not just db as db was null