Access FaaPz/Slim-PDO from container in model


#1

IM trying to access PDO (https://packagist.org/packages/slim/pdo) from the container inside my Models but a blank page loads

app.php
$container[‘pdo’] = function ($container) use ($config) {
return new \Slim\PDO\Database($config[‘db’][‘dsn’], $config[‘db’][‘usr’], $config[‘db’][‘pw’]);
};

user.php
namespace App\Models;

class User extends Model
{

	protected $table = 'users';

	public function attempt($username,$password)
	{

		$selectStatement = $this->pdo->select()->from($table)->where('username', '=', $username);
		$stmt 			 = $selectStatement->execute();
		$data 			 = $stmt->fetch();
	
		if ($data) {
        	return true;
        }else{
        	return false;
        }
		
	}
}

#2

I did a stupid mistake.

this
$this->pdo->select()->from($table)->where(‘username’, ‘=’, $username);
Should be
$this->pdo->select()->from($this->table)->where(‘username’, ‘=’, $username);


#3

Hi rakma.

It looks like I also have a similar problem. Can you show me source code file Model Class and Controller where you use Model User.

Maybe after finished viewing, i can fix code by myself.

Please help me…