PHPackages                             amxm/db - 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. amxm/db

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

amxm/db
=======

DbAdapters

0.62(2y ago)042MITPHP

Since Apr 30Pushed 1y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (16)Used By (0)

PDOAdapter
==========

[](#pdoadapter)

The PDOAdapter class is a class that implements the DbInterface interface, which provides a set of methods for interacting with a database. The class uses the PDO library to connect to a database and execute queries. Here's an overview of the class and its methods:

Class: PDOAdapter Properties:
-----------------------------

[](#class-pdoadapter-properties)

**$db**: An instance of the PDO class that represents the database connection.

**$cache**: A cache object used for caching query results. (This cache object is PSR-16 compatible, and an example of such an object is Memcached)

Methods:
--------

[](#methods)

**\_\_construct(PDO $db, $cache = false)**Constructor method that initializes the class properties. Takes a PDO object as its first parameter and an optional cache object (PSR-16 compatible) as its second parameter.

```
$pdo = new PDO('mysql:dbname=test;host=127.0.0.1', 'username', 'password');
$db = new PDOAdapter($pdo, $memcached);

```

**cache($timeout)**Sets the cache timeout value and returns the object instance.

```
$db->cache(86400)->rows("SELECT * FROM articles ORDER BY date DESC LIMIT 10");

```

**query(string $sql, array $vars = array())**Executes the given SQL query with the given parameters and returns a statement object.

**row(string $sql, array $vars = array())**Executes the given SQL query with the given parameters and returns the first row of the result set as an associative array.

```
$article = $db->row("SELECT * FROM articles WHERE id=?", [$id]);

```

**rows(string $sql, array $vars = array())**Executes the given SQL query with the given parameters and returns all rows of the result set as an array of associative arrays.

```
$articles = $db->rows("SELECT * FROM articles WHERE status=?", ['OK']);

```

**col(string $sql, array $vars = array())**Executes the given SQL query with the given parameters and returns the first column of the first row of the result set.

```
$maxId = $db->col("SELECT max(id) FROM articles");

```

**insert($table, $data)**Inserts a row into the given table with the given data and returns the last inserted ID.

```
 $insertId = $db->insert('articles', [
        'title' => 'All you need is love',
        'status' => 'OK',
        'date' => $db->now(),
        'created_at' => $db->func('NOW()'),
    ]);

```

**insertUpdate($table, $data, $updateData = null)**The insertUpdate method allows inserting a new row into the specified table with the provided data. In case of unique key conflicts (e.g., duplication of values in a unique index), the method updates the existing row in the table based on the provided data. If $updateData is not provided and a key conflict occurs, the data will be updated from $data.

To determine whether data was updated or a new record was added, you can use $db-&gt;rowCount(): if it returns 1, a new record was added; if it returns 2, an existing record was updated. This behavior is consistent with PDO's default behavior.

```
$insertId = $db->insertUpdate('articles', [
        'title' => 'All you need is love',
        'status' => 'OK',
        'date' => $db->now(),
        'created_at' => $db->func('NOW()'),
    ], ['updated_at' => $db->func('NOW()')]);

```

**insertIgnore($table, $data)**

Alias for $db-&gt;insert($table, $data, \['ignore' =&gt; true\]);

**replace($table, $data)**

Alias for $db-&gt;insert($table, $data, \['replace' =&gt; true\]);

**update($table, $data, $where, $vars)**Updates a row in the given table with the given data and variables and returns the number of rows affected.

```
$db->update('articles', [
        'status' => 'BAD',
        'updated_at' => $db->now()
    ], 'id=?', [5]);

```

**func($mysqlFunction)**Returns an object that represents a MySQL function to be used in a query.

```
$ins = ['created_at' => $db->func('NOW()')];
$ins = ['created_at' => $db->func('NOW() + INTERVAL 1 DAY')];

```

**now()**Returns the current date and time in the format "Y-m-d H:i:s". It provides a simple way to replace the MySQL function `NOW()`, and an alternative variant is to use `$db->func('NOW()')`."

```
$ins = ['created_at' => $db->now()];

```

**fetch()**Returns the last fetched row of the result set as an associative array.

```
$db->query("SELECT * from articles WHERE status=?",['OK']);
while($row = $db->fetch()){
	$row['text'] = $db->row("SELECT text FROM articles_text WHERE id=?", $row['id']);
	if ($row['id']>100) break;
}

```

Overall, the PDOAdapter class provides a simple and flexible way to interact with a database using PDO. Its methods allow for easy querying of the database and manipulation of data, and its caching feature helps to improve performance by reducing the number of database queries.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Every ~28 days

Recently: every ~86 days

Total

14

Last Release

752d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14893480?v=4)[Maxim](/maintainers/marnautov)[@marnautov](https://github.com/marnautov)

---

Top Contributors

[![marnautov](https://avatars.githubusercontent.com/u/14893480?v=4)](https://github.com/marnautov "marnautov (22 commits)")

---

Tags

phpdatabasemysqlpdoadapterdb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amxm-db/health.svg)

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

###  Alternatives

[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[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)[riverside/php-orm

PHP ORM micro-library and query builder

111.2k](/packages/riverside-php-orm)

PHPackages © 2026

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