PHPackages                             kora/database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kora/database

ActiveLibrary[Database &amp; ORM](/categories/database)

kora/database
=============

Database for the Kora Framework.

0.1.1(1y ago)12MITPHPPHP ^7.4 || ^8.0

Since Jan 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/koraphp/database)[ Packagist](https://packagist.org/packages/kora/database)[ Docs](https://github.com/koraphp/database)[ RSS](/packages/kora-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Kora\\Database – Quickstart
===========================

[](#koradatabase--quickstart)

A simple and efficient way to interact with MySQL/MariaDB databases.

- **MySQLDatabase**: A secure PDO-based database wrapper for MySQL/MariaDB.
- **Repository**: A convenient CRUD and basic query-building layer on top of MySQLDatabase.

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org/):

```
composer require kora/database
```

Quickstart
----------

[](#quickstart)

### 1. Autoload

[](#1-autoload)

After installing, ensure you include Composer’s autoloader:

```
require_once __DIR__ . '/vendor/autoload.php';
```

### 2. Create a MySQLDatabase instance

[](#2-create-a-mysqldatabase-instance)

```
use Kora\Database\MySQL\MySQLDatabase;

$db = new MySQLDatabase(
    host: '127.0.0.1',
    dbName: 'your_database',
    user: 'your_user',
    password: 'your_password',
    port: 3306 // default is 3306, can omit if desired
);
```

- **SSL Support**: If your environment requires a secure connection, pass `useSSL: true` and provide SSL options.
- **Logging**: Optionally pass a PSR-3 compatible logger for debug/error logging.

### 3. Perform Basic Queries

[](#3-perform-basic-queries)

```
// Example: Insert a row
$rows = $db->execute(
    "INSERT INTO users (username, email) VALUES (:username, :email)",
    ['username' => 'alice', 'email' => 'alice@example.com']
);
echo "Rows inserted: {$rows}\n";

// Fetch a single row
$user = $db->fetchOne(
    "SELECT * FROM users WHERE username = :username",
    ['username' => 'alice']
);
var_dump($user);

// Fetch multiple rows
$users = $db->fetchAll("SELECT * FROM users");
foreach ($users as $user) {
    echo $user['username'], PHP_EOL;
}
```

### 4. Using the Repository Class

[](#4-using-the-repository-class)

The `Repository` offers a high-level CRUD interface plus a mini query builder.

```
use Kora\Database\MySQL\Repository;

// Create a repository for the "users" table, primary key is "id" by default
$userRepo = new Repository($db, 'users', 'id');

// Create a new user
$newUserId = $userRepo->create([
    'username' => 'bob',
    'email'    => 'bob@example.com',
    'status'   => 'active',
]);

// Read a user
$bob = $userRepo->find($newUserId);
echo "Found user: " . $bob['username'] . "\n";

// Update the user
$userRepo->update($newUserId, ['status' => 'inactive']);

// Delete the user
$userRepo->delete($newUserId);
```

#### Query Builder Examples

[](#query-builder-examples)

```
// Get all active users, ordered by creation time
$activeUsers = $userRepo
    ->where('status', '=', 'active')
    ->orderBy('created_at', 'DESC')
    ->get();

// Count how many users have a certain status
$inactiveCount = $userRepo
    ->where('status', '=', 'inactive')
    ->count();

// Check if any records exist with username "alice"
$aliceExists = $userRepo
    ->where('username', '=', 'alice')
    ->exists();
```

### 5. Transactions

[](#5-transactions)

Use the underlying `MySQLDatabase` transactions for multi-step operations:

```
$db->transaction(function (MySQLDatabase $db) {
    // Perform multiple queries that succeed or fail together
    $db->execute("UPDATE accounts SET balance = balance - 100 WHERE user_id = 1");
    $db->execute("UPDATE accounts SET balance = balance + 100 WHERE user_id = 2");
});
```

Next Steps
----------

[](#next-steps)

- **Explore** the rich methods in both `MySQLDatabase` and `Repository` (like `fetchColumn`, `tableExists`, etc.).

That’s it! You now have a simple convenient way to manage MySQL/MariaDB data.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance42

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

484d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e63814623c57ea0f4579845bd92646e29232a68fed08adf09b35da86739b910?d=identicon)[kora](/maintainers/kora)

---

Top Contributors

[![devuri](https://avatars.githubusercontent.com/u/4777400?v=4)](https://github.com/devuri "devuri (11 commits)")

### Embed Badge

![Health badge](/badges/kora-database/health.svg)

```
[![Health](https://phpackages.com/badges/kora-database/health.svg)](https://phpackages.com/packages/kora-database)
```

###  Alternatives

[doctrine/mongodb-odm

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k23.3M302](/packages/doctrine-mongodb-odm)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.4k84.1k1](/packages/getgrav-grav)[basemkhirat/elasticsearch

Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax

402312.0k](/packages/basemkhirat-elasticsearch)[bolt/core

🧿 Bolt Core

585142.5k54](/packages/bolt-core)[doctrine/doctrine-mongo-odm-module

Laminas Module which provides Doctrine MongoDB ODM functionality

86676.6k35](/packages/doctrine-doctrine-mongo-odm-module)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
