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

3.0.0(2mo ago)0481[2 PRs](https://github.com/maggsweb/maggsweb-pdo/pulls)gpl-3.0PHPPHP ^8.2CI failing

Since Jul 12Pushed 2mo 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 3w ago

READMEChangelog (6)Dependencies (2)Versions (15)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

require_once ('MyPDO.php');

$db = new 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
//$result  = $db->fetchRow();           // Single row
//$result  = $db->fetchRow('Array');    // Single row, returned as an array
//$result  = $db->fetchAll('Array');    // Multiple rows, returned as a multi-dimensional array
//$result  = $db->fetchOne();           // Single value
```

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($sql)->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 = array('firstname' => 'Fred', 'surname' => 'Bloggs');

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

### Insert Results

[](#insert-results)

```
if($result){
    echo $db->numRows() . ' records affected';
} else {
    echo $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 = array('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 = array('firstname' => 'Fred 2', 'surname' => 'Bloggs 2');
$where   = "firstname = 'Fred' AND surname = 'Bloggs'";  //'WHERE' is not needed, or spaces

$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 = array('firstname' => 'Fred 2', 'surname' => 'Bloggs 2');
$where   = array('firstname' => 'Fred',   'surname' => 'Bloggs');

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

### Update Results

[](#update-results)

```
if($result){
    echo $db->numRows() . ' records affected';
} else {
    echo $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 = array('surname' => 'Doe');

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

### Delete Results

[](#delete-results)

```
if($result){
    echo $db->numRows() . ' records affected';
} else {
    echo $db->getError();
}
```

---

More examples are provided in 'examples.php'

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity72

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

Recently: every ~412 days

Total

9

Last Release

64d 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

2.0.3 → 3.0.02026-04-21

PHP version history (3 changes)2.0.0PHP ^7.3

1.0.0PHP ^7.1

3.0.0PHP ^8.2

### 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 (130 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.8M74](/packages/ifsnop-mysqldump-php)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k23.1k](/packages/clouddueling-mysqldump-php)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1815.7k12](/packages/popphp-pop-db)[riverside/php-orm

PHP ORM micro-library and query builder

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

PHPackages © 2026

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