Repository navigation
API Database
Caligrafy Quill 2.26.0. Generated from the source by
php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.
Part of Data.
namespace Caligrafy;
class Database extends \stdClassSource: framework/database/Database.php:19
The Database class handles all database connections and global functions that interface directly with the database
Database::connect()Database::persistent()Database::reset()Database::alignTimeZone()Database::dsn()Database::execute()Database::render()Database::toArray()Database::is_Json()Database::connection()Database::endRequest()Database::useConnection()Database::table()Database::transaction()Database::rowCount()Database::lastInsertId()
public static function connect()Connects to the database
Returns the: database connection
Source: framework/database/Database.php:39
public static function persistent($adapter)Whether this process keeps its database connection between requests (2.26.0): DB_PERSISTENT, true by default for MySQL and PostgreSQL in a web server; never on the command line (tests, migrations, the queue: each run is fresh), never for SQLite. DB_PERSISTENT=false connects on every request, as before 2.26.0.
Parameters
$adapter
Source: framework/database/Database.php:62
public static function reset($connection)A reused connection starts clean: a transaction the previous request left open is rolled back (PHP rolls it back at the end of a request too; this is the second lock), and the session time zone is set again by alignTimeZone. PDO checks that a reused connection is alive and opens a new one if the database dropped it.
Parameters
$connection
Source: framework/database/Database.php:79
public static function alignTimeZone($connection, $adapter)MySQL session time zone = PHP's (SERVER_TIMEZONE), so that NOW(), CURRENT_TIMESTAMP columns and the times PHP writes (the audit log) use the same clock. DB_TIMEZONE=server keeps the database server's own time zone.
Parameters
$connection$adapter
Source: framework/database/Database.php:95
public static function dsn($adapter, $host, $dbName, $port = null)Builds the PDO DSN from the DB_* settings DB_PORT is added unless DB_HOST already carries a ';port=' (older workaround)
Parameters
$adapter$host$dbName-
$port, defaultnull
Returns string: the DSN
Source: framework/database/Database.php:112
public static function execute($query, $args = array())Executes PDO Query
Parameters
-
$querystring: defines the query to be executed -
$argsarray, defaultarray(): defines the argument that need to be bound to the query
Returns rendered: result in array or json format
Source: framework/database/Database.php:131
public static function render($result)Result rendered
Parameters
-
$resultarray: defines the result coming from the database in an array format
Returns rendered: result in array or json format depending on the setting
Source: framework/database/Database.php:161
public static function toArray($result)Forces the result to an array
Parameters
-
$resultarray: defines the result coming in either a json or array format
Returns array: $result the result rendered as an array
Source: framework/database/Database.php:179
public static function is_Json($string)Checks if a string i a JSON
Parameters
-
$stringstring: defines the string to be checked
Returns boolean: if the string is a JSON
Source: framework/database/Database.php:197
public static function connection()The PDO connection, connecting on first use (null when DB_ACTIVATE is not true); tests run in its transactions
Source: framework/database/Database.php:206
public static function endRequest()The end of a request in a process that serves many (2.26.0, the async server): a transaction left open is rolled back, the counters forgotten; the connection stays open for the next request
Source: framework/database/Database.php:230
public static function useConnection($connection = null)Uses this PDO connection (a test's in-memory SQLite, a worker's own connection); null connects again on next use
Parameters
-
$connection, defaultnull
Source: framework/database/Database.php:242
public static function table($table)A query builder on a table: Database::table('books')->where('price', '<', 20)->get()
Parameters
-
$tablestring: the table (letters, digits, _)
Returns Query
Source: framework/database/Database.php:253
public static function transaction(callable $callback)Runs $callback in a transaction: committed when it returns, rolled back when it throws (the exception is thrown again). A transaction inside another one (or inside a test's transaction) just runs in the outer one.
Parameters
-
$callbackcallable
Returns mixed: what $callback returns
Source: framework/database/Database.php:263
public static function rowCount()The number of rows the last INSERT, UPDATE or DELETE changed
Source: framework/database/Database.php:291
public static function lastInsertId()Gets Last Inserted Id
Returns int: Last Inserted Id
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)