GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Cycle ORM
  • GitHub
  • Documentation
  • Wippy.ai
  • Spiral Framework
  • RoadRunner

This view

  • Original page
  • New address

GeezerVison is showing cycle-orm.dev — Cycle ORM: Databases - Access Database

  • Table of Contents
  • About Cycle ORM
  • Installation
  • Integrations
  • Upgrade Guide
  • Contributing
  • Issue with Test Case
  • Versioning
  • LICENSE
  • Create, Update, Delete
  • Direct Database Queries
  • Select
  • Custom Repositories
  • Simple Relation
  • Without Annotations
  • Prerequisites
  • Entities
  • Embeddings
  • Relations
  • Has One
  • Has Many
  • Belongs To
  • Refers To
  • Many To Many
  • Embedding Entities
  • Morphed Relations
  • Collections
  • Bulk Loading
  • Basics
  • Extended Builder Usage
  • Querying Relations
  • Complex Queries
  • Security
  • Install
  • UUID
  • Auto Timestamps
  • Soft delete
  • Optimistic lock
  • Hooks
  • Event listener
  • Extensions
  • Events
  • Configuring Schema Builder
  • Manually defined Mapping Schema
  • Dynamic Mapping Schema
  • Column wrappers and typecast
  • DateTime properties
  • Composite PK
  • Installation and Configuration
  • Connect to Database
  • Access Database
  • Profiling and Logging
  • Database Isolation
  • Query Builders
  • Transactions
  • Schema Introspection
  • Schema Declaration
  • Migrations
  • Synchronizing Database Schema (Migrations)
  • Errata
  • About
  • Proxy Mapper
  • Classless Mapper
  • Std Mapper
  • Promise Mapper
  • Mapper extending
  • References
  • Typecasting
  • Customize Schema Defaults
  • Scopes
  • Single Table Inheritance
  • Joined Table Inheritance
  • Caching
  • Pagination
  • Chained Repository
  • Persist Repositories
  • Active Record
  • Schema
  • Entity, Heap, Node, State
  • Entity manager (Unit of Work)
  • Entity Iterator
  • Node Parser
  • Long-Running Applications
  • Commands
  • Testing
  • Limitations
  • Introduction
  • Installation
  • Active Entities
  • Active Query
  • Active Repository
Revision: Wed, 04 Nov 2026 16:26:00 GMT

Database - Access Database

  • Access the Database
  • Run Queries

Follow the configuration instructions here.

#Access the Database

Once DBAL component configured properly, you can access your databases in controllers and services multiple ways:

php
declare(strict_types=1);

require_once "vendor/autoload.php";

use Cycle\Database\Config\DatabaseConfig;
use Cycle\Database\DatabaseManager;
use Cycle\Database\Driver\SQLite\SQLiteDriver;

$dbal = new DatabaseManager(new DatabaseConfig(...));

//Default database
print_r($dbal->database());

//Using alias default which points to primary database
print_r($dbal->database('default'));

//Secondary
print_r($dbal->database('secondary'));

#Run Queries

To run the database query use method query:

php
$db = $dbal->database();

print_r(
    $db->query(
        'SELECT * FROM users WHERE id > ?',
        [
            1
        ]
    )->fetchAll()
);

To execute update or delete statement use the alternative method execute:

php
$db = $dbal->database();

print_r(
    $db->execute(
        'DELETE FROM users WHERE id > ?',
        [
            1
        ]
    ) // number of affected rows 
);

Read how to use query builders here.

← PREVIOUS Connect to Database
NEXT → Profiling and Logging
2.x
2.x
1.x
Edit this page
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.