PHPackages                             christianklisch/ckdb - 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. christianklisch/ckdb

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

christianklisch/ckdb
====================

A flat file key-object nosql database

0.2.1(12y ago)132Apache 2.0PHPPHP &gt;=5.3.0

Since May 1Pushed 11y ago3 watchersCompare

[ Source](https://github.com/christianklisch/ckdb)[ Packagist](https://packagist.org/packages/christianklisch/ckdb)[ Docs](https://github.com/christianklisch/ckdb)[ RSS](/packages/christianklisch-ckdb/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)DependenciesVersions (2)Used By (0)

CKDB v. 0.2.1
=============

[](#ckdb-v-021)

CKDB is a key-object flat file database for php scripts

Use it:

- For small fast websites with simple data model
- If no external database available (e.g. free webspace)
- When small object-based database without complex configuration
- For fast copy between webservers

Features:

- Easy configuration
- Map your entity classes without change them
- key-object based
- Class relations
- Default database functions for insert, update, delete objects
- Repository for select by property value or ranges, order by properties
- Fast indexfile
- Because of one file per entity parallel write access on different entities possible

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

[](#installation)

You can install the script manually using the `require` method:

```
require 'CKDB.php';
```

- Add write permissions for database directory (in configuration 'databasepath')
- Check webspace, because filebased datastore need space

Deploying
---------

[](#deploying)

Include the script in your project either with Composer or via the manual `require` method and create a new instance of the class, using the appropriate parameters if needed:

```
$em = new CKDB($config);
```

Configure
---------

[](#configure)

Set:

- array of paths to entity classes to persist in database (not selected entities won't be saved as own record in database)
- path of database (check write permissions for script). Each entity gets own storage subdirectory
- compression active (not implementet yet)

```
$config = array(
    'entitypaths' => array('path/to/your/entities'),
    'databasepath' => 'database',
    'compression' => 1,
);

$em = new CKDB($config);
```

### Configure your data model

[](#configure-your-data-model)

The following defined class properties will be added to database index.

Define ONE primary key for each class in array:

```
$primkeys = array(
    'User' => 'id'
);
$em->setPrimaryKeys($primkeys);
```

Define foreign keys which you want to use in selection and order functions. Each array value is one field in entitiy 'User':

```
$forkeys = array(
    'User' => array('id', 'firstname', 'email')
);
$em->setForeignKeys($forkeys);
```

Define referenced classes for properties. Instead of object primary key will be saved in database index. If you don't define referenced classes, subclasses will not be saved as own database record and are not searchable by own repository. In this example the field 'homeaddress' referenced to entities of class 'Address':

```
$refclasses = array(
    'User' => array('homeaddress' => 'Address')
);
$em->setReferenceClasses($refclasses);
```

Use CKDB Database
-----------------

[](#use-ckdb-database)

### Default functions

[](#default-functions)

Persist an object with:

```
$u = new User();
$u->setId('4711');
$u->setFirstname('George');
$u->setEmail('george@mail.com');

$em->persist($u);
```

Referenced objects will be persist automatically. After changing your object you have to persist it.

Delete an object with:

```
$em->remove($u);
```

Object is identified by type of class and defined primary key! Don't change primary keys!

### Reindex database

[](#reindex-database)

To rebuild the whole index per entity class use the reIndex()-function;

```
$em->reIndex('User');
```

Method should be called after much changes on index properties or object deletions. Don't call it on time critical processes.

### Search

[](#search)

To search for one or more stored objects you should use a repository:

```
$userRepository = $em->getRepository('User')
```

CKDB provides following methods to find entities after calling find() of repository:

- equals (matching array with field = &gt; value)
- notEquals (matching array with field = &gt; value)
- lt lte (lower than - matching array with field = &gt; value)
- gt gte (lower than - matching array with field = &gt; value)
- in (array key must contain field value)
- notIn (array key must not contain field value)

Furthermore you can sort the results with the sortBy()-method of repository.

Example selection:

```
$userRepository->find()->equals(array('firstname' => 'George'))->gt(array('age' => '50'))->sortBy('age', SORT_DESC)->getResult();
```

This selection searches in field 'firstname' for 'George' with an 'age' older than 50 years (greater than = gt). The users should be sordet descending. The getResult()-method returns an array of found objects in database.

Search in value list with in() and select all Martins and Georges:

```
$userRepository->find()->in('firstname', array('Martin','George'))->getResult();
```

Search in object list with in() and match entries in other array list (i.E. all childs of fathers named Mo Miller):

```
$fathers = $userRepository->find()->equals(array('firstname' => 'Mo', 'lastname' => 'Miller'))->getResult();
$userRepository->find()->in('father', $fathers)->getResult();
```

### Sort

[](#sort)

The sortBy()-method sort the results before returning them. The first parameter defines the sort-field, the second the sort order. You can sort:

- SORT\_ASC ascending
- SORT\_DESC descending

Example

```
$userRepository->find()->gt(array('age' => '50'))->sortBy('age', SORT_DESC)->getResult();
```

Select all users older than 50 years and sort by age descending.

Todos
-----

[](#todos)

- Documentation
- Add exceptions
- Add search-method like()
- Add joining referenced entities

Contributors
------------

[](#contributors)

- Christian Klisch

Copyright and license
---------------------

[](#copyright-and-license)

Copyright 2014 Christian Klisch, released under [the Apache](LICENSE) license.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

4395d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c734fd678c062b95a1e2c3b87711d6ffe18618da157e136d798617f3d012bfb?d=identicon)[christianklisch](/maintainers/christianklisch)

---

Top Contributors

[![christianklisch](https://avatars.githubusercontent.com/u/3337529?v=4)](https://github.com/christianklisch "christianklisch (3 commits)")

---

Tags

phpdatabasefilenosqlflatflatfile

### Embed Badge

![Health badge](/badges/christianklisch-ckdb/health.svg)

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

###  Alternatives

[rakibtg/sleekdb

SleekDB - A NoSQL Database made using PHP

984116.7k19](/packages/rakibtg-sleekdb)[greg0/lazer-database

PHP library to use JSON files like flat-file database

28816.5k4](/packages/greg0-lazer-database)[tbolier/php-rethink-ql

A clean and solid RethinkDB driver for PHP.

5211.7k](/packages/tbolier-php-rethink-ql)[alvin0/database-json-laravel

Create and manage json databases with Laravel

344.3k](/packages/alvin0-database-json-laravel)[f21/paradox

Paradox is an elegant Object Document Mananger (ODM) to use with the ArangoDB Document/Graph database server.

256.8k](/packages/f21-paradox)[eftec/documentstoreone

A flat document store for PHP that allows multiples concurrencies.

124.5k4](/packages/eftec-documentstoreone)

PHPackages © 2026

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