PHPackages                             pontikis/dacapo - 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. pontikis/dacapo

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

pontikis/dacapo
===============

Dacapo - Simple PHP database wrapper

v1.0.2(7y ago)4567[3 issues](https://github.com/pontikis/dacapo/issues)MITPHPPHP ^7.0

Since Apr 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/pontikis/dacapo)[ Packagist](https://packagist.org/packages/pontikis/dacapo)[ Docs](https://github.com/pontikis/dacapo)[ RSS](/packages/pontikis-dacapo/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

Dacapo
======

[](#dacapo)

Dacapo class (Simple PHP database wrapper)

Copyright Christos Pontikis

License MIT [https://raw.github.com/pontikis/dacapo/master/MIT\_LICENSE](https://raw.github.com/pontikis/dacapo/master/MIT_LICENSE)

Overview - Database
-------------------

[](#overview---database)

- Supported RDMBS: MySQLi (or MariaDB), POSTGRESQL
- Simple and clear syntax
- Only prepared statements are used
- Supported Queries: single SELECT, UPDATE, INSERT, DELETE.
- Support of transactions
- Write SQL easily and securely. Use dacapo `sql_placeholder` (? is the default) in place of parameters values. Dacapo will create SQL prepared statements from standard ANSI SQL.

```
$sql = 'SELECT procuct_name FROM products WHERE manufacturer = ? and type IN (?,?,?)';
```

### Remarks

[](#remarks)

- For MYSQLi SELECT prepared statements, `mysqlnd` is required
- Persistent database connection NOT supported.
- BLOB columns NOT supported
- avoid boolean columns, use integer instead (1,0)
- Use `$ds->execute()` to execute one or usually multiple SQL statements (e.g. an SQL script). You cannot use prepared statements here.

### About Exceptions

[](#about-exceptions)

You SHOULD create custom wrappers in your application to catch exceptions.

Dacapo Error Handler will throw `DacapoErrorException`.

If you choose to not use Dacapo Error Handler you will define type of Exception in your own Error Handler.

### About Postgresql sequences

[](#about-postgresql-sequences)

When you execute an INSERT query in Postgres you have also to query a sequence if you want to get the last inserted value in Primary Key column. In this case use `setQueryInsertPgSequence()`. There are three options:

- `self::PG_SEQUENCE_NAME_AUTO` in this case sequence name will be automatically constructed as `tablename_id_seq`. This is the default setting (ideal for SERIAL columns)
- `null` (in the rare case when no Primary key is defined)
- the sequence real name

REMEMBER that `query_insert_pg_sequence` will be reset to default `self::PG_SEQUENCE_NAME_AUTO` after each INSERT query.

Documentation
-------------

[](#documentation)

For HTML documentation, see `docs/doxygen/html/` folder (open `index.html` file in a browser).

Install
-------

[](#install)

using Composer (recommended)

```
composer require pontikis/dacapo
```

or the old-school way:

```
require_once 'path/to/Dacapo.php';
require_once 'path/to/DacapoErrorException.php';
```

Usage - examples
----------------

[](#usage---examples)

### Create instance

[](#create-instance)

```
use Pontikis\Database\Dacapo;
use Pontikis\Database\DacapoErrorException;

$db_settings = [
	'rdbms' => Dacapo::RDBMS_POSTGRES, // or Dacapo::RDBMS_MYSQLI for MySQL/MariaDB
	'db_server' => 'localhost',
	'db_user' => 'foo',
	'db_passwd' => 'bar',
	'db_name' => 'baz',
];

try {
	$ds = new Dacapo($db_settings);
} catch (Exception $e) {
	// your code here
}
```

### Select

[](#select)

```
$sql = 'SELECT id, firstname, lastname FROM customers WHERE lastname LIKE ?';
$bind_params = ['%' . $str . '%'];
try {
	$ds->select($sql, $bind_params);
	$customers = $ds->getData();
} catch (DacapoErrorException $e) {
	// your code here
}
```

#### Iterate data

[](#iterate-data)

```
if($ds->getNumRows() > 0) {
	foreach($customers as $customer) {
		$id = $customer['id'];
		$lastname = $customer['lastname'];
		$firstname = $customer['firstname'];
	}
}
```

### Select row

[](#select-row)

```
$sql = 'SELECT firstname, lastname FROM customers WHERE id = ?';
$bind_params = [$id];
try {
	$ds->select($sql, $bind_params);
	if(1 === $ds->getNumRows()) {
		$customer = $ds->getRow();
		$firstname = $customer['firstname'];
		$lastname = $customer['lastname'];
	}
} catch (DacapoErrorException $e) {
	// your code here
}
```

### Insert

[](#insert)

```
$sql = 'INSERT INTO customers (firstname, lastname) VALUES (?,?)';
$bind_params = [$firstname, $lastname];
try {
	$ds->insert($sql, $bind_params);
	$new_customer_id = $ds->getInsertId();
} catch (DacapoErrorException $e) {
	// your code here
}
```

### Update

[](#update)

```
$sql = 'UPDATE customers SET category = ? WHERE balance > ?';
$bind_params = [$category, $balance];
try {
	$ds->update($sql, $bind_params);
	$affected_rows = $ds->getAffectedRows();
} catch (DacapoErrorException $e) {
	// your code here
}
```

### Delete

[](#delete)

```
$sql = 'DELETE FROM customers WHERE category = ?';
$bind_params = [$category];
try {
	$ds->delete($sql, $bind_params);
	$affected_rows = $ds->getAffectedRows();
} catch (DacapoErrorException $e) {
	// your code here
}
```

### Transactions

[](#transactions)

```
try {
	$ds->beginTrans();

	// delete from customers
	$sql = 'DELETE FROM customers WHERE id = ?';
	$bind_params = [$customers_id];
	$ds->delete($sql, $bind_params);

	// delete from demographics
	$sql = 'DELETE FROM demographics WHERE id = ?';
	$bind_params = [$customer_demographics_id];
	$ds->delete($sql, $bind_params);

	$ds->commitTrans();
} catch (DacapoErrorException $e) {
	$ds->rollbackTrans();
	// your code here
}
```

### Utility functions

[](#utility-functions)

#### lower

[](#lower)

```
// check for unique username (CASE IN-SENSITIVE)
$sql = "SELECT count('id') as total_rows FROM users WHERE {$ds->lower('username')} = ?";
$bind_params = [mb_strtolower($username)];
$ds->select($sql, $bind_params);
if($ds->getNumRows() > 0) {
	echo 'Username in use...';
}
```

#### limit

[](#limit)

```
$limitSQL = $ds->limit($rows_per_page, ($page_num - 1) * $rows_per_page);
```

PHPUnit
-------

[](#phpunit)

Tests performed in Debian 9 Linux server with

- php 7
- MariaDB Ver 15.1 Distrib 10.1.26-MariaDB (similar to MySQL 5.7)
- Postgres 9.6.7

Test databases are provided in `tests/dbdata` folder. Customize credentials in `tests/phpunit.xml`. First copy `phpunit.dest.xml` to `phpunit.xml`

### MySQL tests

[](#mysql-tests)

Test `connect` and `select`
---------------------------

[](#test-connect-and-select)

```
./vendor/bin/phpunit --configuration tests/phpunit.xml tests/MySQLTest.php

```

mysqli timout make some tests slow. Run them once and then use:

```
./vendor/bin/phpunit --enforce-time-limit --configuration tests/phpunit.xml tests/MySQLTest.php

```

In this case PHP\_Invoker is needed

CUD tests Insert (C) Update (U) and Delete (D) operations and Transactions
--------------------------------------------------------------------------

[](#cud-tests-insert-c-update-u-and-delete-d-operations-and-transactions)

```
./vendor/bin/phpunit --configuration tests/phpunit.xml tests/MySQLCUDTest.php

```

### Postgres tests

[](#postgres-tests)

Test `connect` and `select`
---------------------------

[](#test-connect-and-select-1)

```
./vendor/bin/phpunit  --configuration tests/phpunit.xml tests/PostgresqlTest.php

```

CUD tests Insert (C) Update (U) and Delete (D) operations and Transactions
--------------------------------------------------------------------------

[](#cud-tests-insert-c-update-u-and-delete-d-operations-and-transactions-1)

```
./vendor/bin/phpunit  --configuration tests/phpunit.xml tests/PostgresqlCUDTest.php

```

### Run certain test eg testConnectFails1()

[](#run-certain-test-eg-testconnectfails1)

```
./vendor/bin/phpunit  --configuration tests/phpunit.xml tests/PostgresqlTest.php --filter '/testConnectFails1$/'

```

You cannot use `--filter` with *CUD* tests. Actually every *CUD* test depends on previous.

Contribution
------------

[](#contribution)

Your contribution is welcomed.

- Pull requests are accepted only in `dev` branch.
- Remember to also submit the relevant PHPUnit tests.
- Review is always required.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance5

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~20 days

Total

5

Last Release

2852d ago

Major Versions

v0.9.3 → v1.0.02018-06-11

PHP version history (2 changes)v0.9.2PHP ^5.4|^7.0

v1.0.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdfb9925cab320f240a394db187b02e4b3af9a054d1e23e749019112cb119af2?d=identicon)[pontikis](/maintainers/pontikis)

---

Top Contributors

[![pontikis](https://avatars.githubusercontent.com/u/814012?v=4)](https://github.com/pontikis "pontikis (80 commits)")

---

Tags

classdatabasemariadbmysqlmysqliphpphp-databasepostgresqlprepared-statementstransactionwrapperphpdatabasemysqlpostgresqlmariadbwrapper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pontikis-dacapo/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)[moharrum/laravel-adminer

Adminer database management tool for your Laravel application.

451.0k](/packages/moharrum-laravel-adminer)

PHPackages © 2026

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