Awesome Open Source
Awesome Open Source

Laminas-db Adapter for PHP-Casbin

Build Status Coverage Status Latest Stable Version Total Downloads License

Laminas-db adapter for PHP-Casbin.

The list of officially supported drivers:

  • IbmDb2: The ext/ibm_db2 driver
  • Mysqli: The ext/mysqli driver
  • Oci8: The ext/oci8 driver
  • Pgsql: The ext/pgsql driver
  • Sqlsrv: The ext/sqlsrv driver (from Microsoft)
  • Pdo_Mysql: MySQL via the PDO extension
  • Pdo_Sqlite: SQLite via the PDO extension
  • Pdo_Pgsql: PostgreSQL via the PDO extension


Use Composer.

composer require casbin/laminas-db-adapter


Before using it, you need to create a table named casbin_rule for Casbin to store the policy.

Take mysql as an example:

CREATE TABLE `casbin_rule` (
  `ptype` varchar(255) NOT NULL,
  `v0` varchar(255) DEFAULT NULL,
  `v1` varchar(255) DEFAULT NULL,
  `v2` varchar(255) DEFAULT NULL,
  `v3` varchar(255) DEFAULT NULL,
  `v4` varchar(255) DEFAULT NULL,
  `v5` varchar(255) DEFAULT NULL

Then you can start like this:

require_once './vendor/autoload.php';

use Casbin\Enforcer;
use Casbin\Util\Log;
use CasbinAdapter\LaminasDb\Adapter;

$adapter = new Adapter([
	'driver' => 'Pdo_Mysql', // IbmDb2, Mysqli, Oci8, Pgsql, Sqlsrv, Pdo_Mysql, Pdo_Sqlite, Pdo_Pgsql
	'hostname' => '',
	'database' => 'test',
	'username' => 'root',
	'password' => '',
	'port' => '3306',

$e = new Enforcer('path/to/model.conf', $adapter);

$sub = "alice"; // the user that wants to access a resource.
$obj = "data1"; // the resource that is going to be accessed.
$act = "read"; // the operation that the user performs on the resource.

if ($e->enforce($sub, $obj, $act) === true) {
    // permit alice to read data1
} else {
    // deny the request, show an error

Getting Help


This project is licensed under the Apache 2.0 license.

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Php (285,984
Driver (18,449
Permissions (11,610
Adapter (11,232
Authorization (5,853
Acl (2,435
Pdo (1,803
Rbac (1,371
Access Control (1,113
Casbin (286
Casbin Adapter (13
Laminas Db (3