https://github.com/modxcms/xpdo
xPDO Object Relational Bridge for PHP
https://github.com/modxcms/xpdo
Last synced: 2 months ago
JSON representation
xPDO Object Relational Bridge for PHP
- Host: GitHub
- URL: https://github.com/modxcms/xpdo
- Owner: modxcms
- License: gpl-2.0
- Created: 2010-07-26T18:10:46.000Z (almost 15 years ago)
- Default Branch: 3.x
- Last Pushed: 2024-04-04T16:20:02.000Z (about 1 year ago)
- Last Synced: 2024-04-14T01:49:53.349Z (about 1 year ago)
- Language: PHP
- Homepage: http://xpdo.org/
- Size: 2.49 MB
- Stars: 72
- Watchers: 20
- Forks: 55
- Open Issues: 58
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE
Awesome Lists containing this project
README
# xPDO O/RB v3
[](https://github.com/modxcms/xpdo/workflows/CI/badge.svg?branch=3.x)
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.
```php
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' => [],
],
],
]);
```