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 today

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

22

—

LowBetter than 21% of packages

Maintenance39

Infrequent updates — may be unmaintained

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

530d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1036193?v=4)[preet](/maintainers/kora)[@kora](https://github.com/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

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[getgrav/grav

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

15.6k86.4k1](/packages/getgrav-grav)[doctrine/mongodb-odm

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

1.1k24.5M358](/packages/doctrine-mongodb-odm)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)

PHPackages © 2026

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