Using the PDO storage classes - cloudmanic/oauth2-server GitHub Wiki

Instead of implementing the storage intefaces yourself you can use a build in PDO driver which implements them already.

First add "zetacomponents/database": "1.4.6" to the "require" key in your composer.json file. Then run composer update.

Then instantiate the PDO factory class with either a DSN string or an array of parameters:

// Config array example
$db = new League\OAuth2\Server\Storage\PDO\Db(array(
    'username'  =>  'dbuser',
    'password'  =>  'dbpass',
    'database'  =>  'oauth',
    'socket'    =>  '/Applications/MAMP/tmp/mysql/mysql.sock',
    'type'  =>  'mysql'
));

// DNS example
$db = new League\OAuth2\Server\Storage\PDO\Db('mysql://dbuser:dbpass@localhost/oauth');

Then you can inject the PDO storage classes into the authorization server:

$server = new League\OAuth2\Server\Authorization(
    new League\OAuth2\Server\Storage\PDO\Client($db),
    new League\OAuth2\Server\Storage\PDO\Session($db),
    new League\OAuth2\Server\Storage\PDO\Scope($db)
);