xpdo / xpdo
A PDO-based Object/Relational Bridge Library
Installs: 69 009
Dependents: 2
Suggesters: 0
Security: 0
Stars: 71
Watchers: 19
Forks: 53
Open Issues: 61
Requires
- php: >=7.2.5
- ext-json: *
- ext-pdo: *
- ext-simplexml: *
- psr/container: ^1.1 || ^2.0.1
- symfony/console: ^5.4
Requires (Dev)
- yoast/phpunit-polyfills: ^1.0
Suggests
- ext-redis: Allows caching using Redis
README
xPDO is an ultra-light object-relational bridge library for PHP. It is a standalone library and can be used with any framework or DI container.
Installation
xPDO can be installed in your project via composer:
composer require xpdo/xpdo
Usage
The \xPDO\xPDO
class is the main point of access to the framework. Provide a configuration array describing the connection(s) you want to establish when creating an instance of the class.
require __DIR__ . '/../vendor/autoload.php'; $xpdoMySQL = \xPDO\xPDO::getInstance('aMySQLDatabase', [ \xPDO\xPDO::OPT_CACHE_PATH => __DIR__ . '/../cache/', \xPDO\xPDO::OPT_HYDRATE_FIELDS => true, \xPDO\xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, \xPDO\xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, \xPDO\xPDO::OPT_CONNECTIONS => [ [ 'dsn' => 'mysql:host=localhost;dbname=xpdotest;charset=utf8', 'username' => 'test', 'password' => 'test', 'options' => [ \xPDO\xPDO::OPT_CONN_MUTABLE => true, ], 'driverOptions' => [], ], ], ]); $xpdoSQLite = \xPDO\xPDO::getInstance('aSQLiteDatabase', [ \xPDO\xPDO::OPT_CACHE_PATH => __DIR__ . '/../cache/', \xPDO\xPDO::OPT_HYDRATE_FIELDS => true, \xPDO\xPDO::OPT_HYDRATE_RELATED_OBJECTS => true, \xPDO\xPDO::OPT_HYDRATE_ADHOC_FIELDS => true, \xPDO\xPDO::OPT_CONNECTIONS => [ [ 'dsn' => 'sqlite:path/to/a/database', 'username' => '', 'password' => '', 'options' => [ \xPDO\xPDO::OPT_CONN_MUTABLE => true, ], 'driverOptions' => [], ], ], ]);