casbin/database-adapter

Database adapter for php-casbin.

Installs: 101 295

Dependents: 6

Suggesters: 0

Security: 0

Stars: 30

Watchers: 4

Forks: 6

Open Issues: 0

pkg:composer/casbin/database-adapter

v2.1.0 2025-05-17 15:35 UTC

This package is auto-updated.

Last update: 2025-12-17 16:52:15 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

Database adapter for PHP-Casbin.

The current supported databases are:

type database
mysql MySQL
pgsql PostgreSQL
sqlite SQLite
sqlsrv SqlServer

Installation

Use Composer

composer require casbin/database-adapter 

Usage

require_once './vendor/autoload.php'; use Casbin\Enforcer; use Casbin\Util\Log; use CasbinAdapter\Database\Adapter as DatabaseAdapter; $config = [ 'type' => 'mysql', // mysql,pgsql,sqlite,sqlsrv 'hostname' => '127.0.0.1', 'database' => 'test', 'username' => 'root', 'password' => 'abc-123', 'hostport' => '3306', ]; $adapter = DatabaseAdapter::newAdapter($config); $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

License

This project is licensed under the Apache 2.0 license.