PHPackages                             javanile/hamper - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. javanile/hamper

ActiveLibrary[Testing &amp; Quality](/categories/testing)

javanile/hamper
===============

Developer friendly database library for vtiger

0.0.4(5y ago)5292[1 issues](https://github.com/javanile/hamper/issues)MITPHPPHP ^7.0CI failing

Since May 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/javanile/hamper)[ Packagist](https://packagist.org/packages/javanile/hamper)[ RSS](/packages/javanile-hamper/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

Hamper DB
=========

[](#hamper-db)

Developer friendly database library for vtiger. Hamper improove the code quality and the readbility of your PHP code around database access and manipulation.

Why I use it?
-------------

[](#why-i-use-it)

Here is a list of compelling reasons to use it

- Avoid old-style loop over results.
- Use by default associative array for fields.

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

[](#installation)

You can install the package via composer:

```
composer require javanile/hamper
```

Usage
-----

[](#usage)

You simply get your `$hdb` object to access on database

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

use Javanile\Hamper\Hamper;

$hdb = Hamper::getInstance();
```

📃 Documentation
---------------

[](#-documentation)

> 😎 The documentation lists all the functions you can use to make the code simple and easy to read.

The access you have on the data inside the database is based on extraction methods that return `array`and that you can easily manipulate with `foreach`. Use the functions well because they allow you to take a single record or a list of records or all the values of a column. Before starting to use it, read the list of functions carefully, and you will automatically use the best one based on the context. For each function you are also presented, the **"😿 Legacy"**, the version of the old style Vtiger code you can replace with Hamper functions, comparing them, and you will realize how Hamper improves your work.

### All Functions

[](#all-functions)

#### The following methods are used to manipulate records into database

[](#the-following-methods-are-used-to-manipulate-records-into-database)

- [Execute query](#-execute-query) - `$hdb->query(...)`
- [Get a single record](#-get-a-single-record) - `$hdb->fetch(...)`
- [Get a list of records](#-get-a-list-of-records) - `$hdb->fetchAll(...)`
- [Get a value from record](#-get-a-value-from-record) - `$hdb->fetchValue(...)`
- [Get value by key column](#-get-value-by-key-column) - `$hdb->value(...)`
- [Check if record exists](#-check-if-record-exists) - `$hdb->exists(...)`
- [Insert a record](#-insert-a-record) - `$hdb->insert(...)`
- [Get last ID](#-get-last-id) - `$hdb->lastInsertId(...)`
- [Update a single record](#-update-a-single-record) - `$hdb->update(...)`
- [Delete a single record](#-delete-a-single-record) - `$hdb->delete(...)`

#### The following methods are used to manipulate database tables and fields

[](#the-following-methods-are-used-to-manipulate-database-tables-and-fields)

- [Create new table](#-create-new-table) - `$hdb->create(...)`

---

`¶` Execute query
-----------------

[](#-execute-query)

Executes the given parametric query

#### Usage

[](#usage-1)

```
$hdb->query($sql, $params = [], $options = [])

```

#### Examples

[](#examples)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy)

Please, replace this kind of legacy code with the `$hdb->query(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Get a single record
-----------------------

[](#-get-a-single-record)

Fetches the next row from the result set rows by the given parametric query.

#### Usage

[](#usage-2)

```
$hdb->fetch($sql, $params = [], $options = [])

```

#### Examples

[](#examples-1)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-1)

Please, replace this kind of legacy code with the `$hdb->fetch(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Get a list of records
-------------------------

[](#-get-a-list-of-records)

Returns an array containing all of the result set rows by the given parametric query.

#### Usage

[](#usage-3)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-2)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-2)

Please, replace this kind of legacy code with the `$hdb->fetchAll(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Get a value from record
---------------------------

[](#-get-a-value-from-record)

Fetches the next row from the result set rows by the given parametric query.

#### Usage

[](#usage-4)

```
$hdb->fetchValue($sql, $params = [], $options = [])

```

#### Examples

[](#examples-3)

This method is useful to handle this situations

```
$crmId = $hdb->fetchValue("SELECT crmid FROM vtiger_crmentity WHERE setype=? AND deleted=0", [$module]);
```

#### 😿 Legacy

[](#-legacy-3)

Please, replace this kind of legacy code with the `$hdb->fetchValue(...)` function

```
$adb = \PearDatabase::getInstance();
$result = $adb->pquery("SELECT tabid FROM vtiger_tab WHERE name=?", [$setype]);
$tabId = $adb->query_result($result, 0, "tabid");
```

[\[back to top ☝\]](#documentation)

---

`¶` Get value by key column
---------------------------

[](#-get-value-by-key-column)

Execute a query to check if record with specific key and value exists.

#### Usage

[](#usage-5)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-4)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-4)

Please, replace this kind of legacy code with the `$hdb->value(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Check if record exists
--------------------------

[](#-check-if-record-exists)

Execute a query to check if record with specific key and value exists.

#### Usage

[](#usage-6)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-5)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-5)

Please, replace this kind of legacy code with the `$hdb->exists(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Insert a record
-------------------

[](#-insert-a-record)

Inserts the given record within the selected table.

#### Usage

[](#usage-7)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-6)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-6)

Please, replace this kind of legacy code with the `$hdb->insert(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Get last ID
---------------

[](#-get-last-id)

Return last insert ID value for the selected table.

#### Usage

[](#usage-8)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-7)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-7)

Please, replace this kind of legacy code with the `$hdb->lastInsertId(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Update a single record
--------------------------

[](#-update-a-single-record)

Updates the given record with the given data.

#### Usage

[](#usage-9)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-8)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-8)

Please, replace this kind of legacy code with the `$hdb->update(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Delete a single record
--------------------------

[](#-delete-a-single-record)

Deletes the given record within the given table.

#### Usage

[](#usage-10)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-9)

This method is useful to handle this situations

```
// Execute simple query
$hdb->query("SET NAMES utf8");
```

```
// Execute prepare query
$hdb->query("UPDATE vtiger_users SET language = ? WHERE user_name = ?", ["en_us", "admin"]);
```

#### 😿 Legacy

[](#-legacy-9)

Please, replace this kind of legacy code with the `$hdb->delete(...)` function

[\[back to top ☝\]](#documentation)

---

`¶` Create new table
--------------------

[](#-create-new-table)

#### Usage

[](#usage-11)

```
query($sql, $params = [], $options = [])

```

#### Examples

[](#examples-10)

This method is useful to handle this situations

#### 😿 Legacy

[](#-legacy-10)

Please, replace this kind of legacy code with the `$hdb->create(...)` function

[\[back to top ☝\]](#documentation)

---

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ make install
```

```
$ make tdd take=tests/HamperDatabaseTest.php
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Socialware
----------

[](#socialware)

We highly appreciate if you create a social post on Twitter with following button

[![Share on Twitter](https://camo.githubusercontent.com/084e163e2cabb4af02af266c81e1dbe5a825917e793596a9d74b6dbf0aeb9382/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d73686172652532306f6e253230747769747465722d626c75653f6c6f676f3d74776974746572267374796c653d666f722d7468652d6261646765)](https://twitter.com/intent/tweet?text=Hello%20world)

Credits
-------

[](#credits)

This project exists thanks to all the people who contribute.

- [Francesco Bianco](https://github.com/francescobianco)
- [All Contributors](https://github.com/javanile/hamper/graphs/contributors)

Support us
----------

[](#support-us)

Javanile is a community project agency based in Sicily, Italy. You'll find an overview of all our projects [on our website](https://www.javanile.org).

Does your business depend on our contributions? Reach out us on [Patreon](https://www.patreon.com/javanile).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/javanile/hamper/blob/main/LICENSE) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.5% 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 ~14 days

Total

4

Last Release

2149d ago

### Community

Maintainers

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

---

Top Contributors

[![francescobianco](https://avatars.githubusercontent.com/u/472171?v=4)](https://github.com/francescobianco "francescobianco (105 commits)")[![rc2pc2](https://avatars.githubusercontent.com/u/3359943?v=4)](https://github.com/rc2pc2 "rc2pc2 (5 commits)")

---

Tags

adodbcode-qualitydatabase-librarydatabase-manipulationdbdeveloper-friendlymodern-phpphpphp8vtigervtiger-crm-exploitvtigercrm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/javanile-hamper/health.svg)

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

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

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