Secure, multiple SQL dialects (MySQL, PostgreSQL, SQLite, SQLServer), schema introspection, schema declaration, smart identifier wrappers, database partitions, query builders, nested queries.
- Installation and Configuration
- Access Database
- Database Isolation
- Query Builders
- Transactions
- Schema Introspection
- Schema Declaration
- Migrations
- Errata
Make sure that your server is configured with following PHP version and extensions:
- PHP 8.0+
- PDO Extension with desired database drivers
To install the component:
composer require cycle/databaseGiven example demonstrates the connection to SQLite database, creation of table schema, data insertion and selection:
<?phpdeclare(strict_types=1);
require_once"vendor/autoload.php";
useCycle\Database\Config;
useCycle\Database\DatabaseManager;
$dbm = newDatabaseManager(newConfig\DatabaseConfig([
'databases' => [
'default' => ['connection' => 'sqlite'],
],
'connections' => [
'sqlite' => newConfig\SQLiteDriverConfig(
connection: newConfig\SQLite\FileConnectionConfig(
database: 'runtime/database.db'
),
),
],
]));
$users = $dbm->database('default')->table('users');
// create or update table schema$schema = $users->getSchema();
$schema->primary('id');
$schema->string('name');
$schema->datetime('created_at');
$schema->datetime('updated_at');
$schema->save();
// insert data$users->insertOne([
'name' => 'test',
'created_at' => newDateTimeImmutable(),
'updated_at' => newDateTimeImmutable(), ]);
// select dataforeach ($users->select()->where(['name' => 'test']) as$u) {
print_r($u);
}MIT License (MIT). Please see LICENSE for more information. Maintained
by Spiral Scout.
