PHPackages                             maggsweb/maggsweb-pdo - 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. maggsweb/maggsweb-pdo

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

maggsweb/maggsweb-pdo
=====================

PDO Database Wrapper for PHP

2.0.3(4y ago)0471gpl-3.0PHPPHP ^7.3CI failing

Since Jul 12Pushed 4y agoCompare

[ Source](https://github.com/maggsweb/maggsweb-pdo)[ Packagist](https://packagist.org/packages/maggsweb/maggsweb-pdo)[ Docs](https://maggsweb.github.io/maggsweb-pdo/)[ RSS](/packages/maggsweb-maggsweb-pdo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (11)Used By (0)

[![StyleCI](https://camo.githubusercontent.com/189515d57ef3b5d7581c707a8ce1b1a4e0b7a7c76151aeeac0336b72c43c00d8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f35303137373339352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/50177395)

Maggsweb PDO
============

[](#maggsweb-pdo)

An easy-to-use PDO Database wrapper for PHP &amp; MySQL

---

### Table of Contents

[](#table-of-contents)

**[Initialization](#initialization)**
**[Query](#query)**
**[Insert Records](#insert-records)**
**[Update Records](#update-records)**
**[Delete Records](#delete-records)**

---

Initialization
--------------

[](#initialization)

To use this class, set your database connection constants, download and include 'MyPDO.php' into your project and instantiate a database connection.

```
define('DBHOST', '');  //eg: 127.0.0.1
define('DBUSER', '');  //eg: root
define('DBNAME', '');  //eg: admin
define('DBPASS', '');  //eg: password

$db = new Maggsweb\MyPDO((DBHOST, DBUSER, DBNAME, DBPASS);
```

---

Query
-----

[](#query)

#### Run a query, any query..

[](#run-a-query-any-query)

To execute a string of SQL, pass the complete SQL string to **-&gt;query**

```
$sql = "INSERT INTO `names` VALUES
            (NULL, 'Joe',  'Bloggs'),
            (NULL, 'John', 'Bloggs'),
            (NULL, 'Jane', 'Bloggs');";

$db->query($sql);

$result = $db->execute();
```

Call **-&gt;execute** to execute the query. This returns true|false;

#### Run a query and return the results

[](#run-a-query-and-return-the-results)

To return the results from **-&gt;query** for use call **-&gt;fetchAll()** for multiple rows, **-&gt;fetchRow** for a single row or **-&gt;fetchOne** for a single value. Results are returned as an Array of Objects an Object or a value. Optionally, passing 'Array' to the fetch functions will return results as a Multi-dimensional Array.

```
$sql = "SELECT * FROM `names`";

$db->query($sql);

$results = $db->fetchAll();           // Multiple rows, returned and an Object Array
$results = $db->fetchAll('Array');    // Multiple rows, returned as a multi-dimensional array

$sql = "SELECT * FROM `names` LIMIT 1";
$db->query($sql);

$result  = $db->fetchRow();           // Single row, returned as an Object
$result  = $db->fetchRow('Array');    // Single row, returned as an Array

$sql = "SELECT name FROM `names` LIMIT 1";
$db->query($sql);

$result  = $db->fetchOne();           // Single value, returned as a String
```

On success, **$result** will be an Object Array (fetchAll) or an Object (fetchRow) or a value (fetchOne)

On failure, call **-&gt;getError** to display the SQL error message

#### Run a query using 'bound' params and return results

[](#run-a-query--using-bound-params-and-return-results)

To bind parameters to a query, pass the column identifier and value to **-&gt;bind()**. Repeat this for each bound parameter in order.

```
$sql = "SELECT * FROM `names` WHERE firstname = :firstname";

$db->query($sql);

$db->bind(':firstname', 'Chris');

$results = $db->fetchAll();

// or

$results = $db->query("SELECT * FROM `names` WHERE firstname = :firstname")
              ->bind(':firstname', 'Chris')
              ->fetchAll();
```

### Query Results

[](#query-results)

On failure, call **-&gt;getError** to display the SQL error message

```
if ($results) {
    foreach ($results as $result) {
        echo $result->{$column};
    }
} else {
    echo $db->getError();
}
```

---

Insert Records
--------------

[](#insert-records)

#### Insert a record using 'bind' params

[](#insert-a-record-using-bind-params)

```
$table   = 'names';
$columns = ['firstname' => 'Fred', 'surname' => 'Bloggs'];

$result = $db->insert($table, $columns);
```

### Insert Results

[](#insert-results)

```
echo $result
    ? $db->numRows() . ' records affected'
    : $db->getError();
```

### Last Insert ID

[](#last-insert-id)

```
$id = $db->insertID();
```

---

Update Records
--------------

[](#update-records)

#### Update (all) records using 'bind' params

[](#update-all-records-using-bind-params)

```
$table   = 'names';
$columns = ['firstname' => 'Fred', 'surname' => 'Bloggs'];

$result = $db->update($table, $columns);
```

#### Update records using 'bind' params and 'where' string

[](#update-records-using-bind-params-and-where-string)

```
$table   = 'names';
$columns = ['firstname' => 'Fred 2', 'surname' => 'Bloggs 2';
$where   = "firstname = 'Fred' AND surname = 'Bloggs'";  //'WHERE' is not needed

$result = $db->update($table, $columns, $where);
```

#### Update specific records using 'bind' params and 'where'

[](#update-specific-records-using-bind-params-and-where)

```
$table   = 'names';
$columns = ['firstname' => 'Fred 2', 'surname' => 'Bloggs 2'];
$where   = ['firstname' => 'Fred',   'surname' => 'Bloggs'];

$result = $db->update($table,$columns,$where);
```

### Update Results

[](#update-results)

```
echo $result
    ? $db->numRows() . ' records affected'
    : $db->getError();
```

---

Delete Records
--------------

[](#delete-records)

#### Delete records using a 'where' string

[](#delete-records-using-a-where-string)

```
$table  = 'names';
$where  = "surname = 'Doe'";

$result = $db->delete($table, $where);
```

#### Delete records using a 'where' array

[](#delete-records-using-a-where-array)

```
$table = 'names';
$where = ['surname' => 'Doe'];

$result = $db->delete($table, $where);
```

### Delete Results

[](#delete-results)

```
echo $result
    ? $db->numRows() . ' records affected'
    : $db->getError();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~17 days

Recently: every ~6 days

Total

8

Last Release

1643d ago

Major Versions

1.0.1 → 2.0.12021-10-15

1.0.2 → 2.0.22021-10-15

1.0.3 → 2.0.32021-11-08

PHP version history (2 changes)2.0.0PHP ^7.3

1.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/20d556e168cc7e96580fd827a84e88c076cc483172990a94a29591eae9b810e2?d=identicon)[maggsweb](/maintainers/maggsweb)

---

Top Contributors

[![maggsweb](https://avatars.githubusercontent.com/u/196674?v=4)](https://github.com/maggsweb "maggsweb (141 commits)")

---

Tags

phpdatabasemysqlpdo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maggsweb-maggsweb-pdo/health.svg)

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

###  Alternatives

[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[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)
