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

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

kovsky0/pdo-wrapper
===================

Simple PDO wrapper - a collection of crud methods for working with a database this includes selecting, inserting, updating and deleting records.

010PHP

Since Sep 13Pushed 8y agoCompare

[ Source](https://github.com/kovsky0/pdo-wrapper)[ Packagist](https://packagist.org/packages/kovsky0/pdo-wrapper)[ RSS](/packages/kovsky0-pdo-wrapper/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PDO Wrapper
===========

[](#pdo-wrapper)

This PDO wrapper, is a collection of crud methods for working with a database this includes selecting, inserting, updating and deleting records.

Install
-------

[](#install)

To install place this class into the project folder and include the class, then set the db credentials. Finally create an instance of the classes by calling it's get method.

This wrapper makes use of a single database connection further connections attempts will reuse the already open connections, if not already connected.

```
include('database.php');

//db properties
define('DB_TYPE','mysql');
define('DB_HOST','localhost');
define('DB_USER','username');
define('DB_PASS','password');
define('DB_NAME','database name');

// make a connection to mysql here
$db = Database::get();
```

To make a connection to another database pass an array containing the following:

```
$db = Database::get(array(
	'type' => 'mysql',
	'host' => 'localhost',
	'name' => 'dbname',
	'user' => 'dbusername'
	'pass' => 'password'
));

```

Usage examples
==============

[](#usage-examples)

Select:
-------

[](#select)

```
$db->select("column FROM table");
```

To select data based on user data instead of passing the data to the query directly use a prepared statement, this is safer and stops any attempt at sql injections.

```
$db->select("username FROM members WHERE memberID = :id and email = :email", array(':id' => 1, ':email' => 'someone@domain.com'));
```

The above query will return the username from the members table where the memberID and email match. The memberID and email is passed seperartly in an array.

Instead of passing in an id and email to the query directly a placeholder is used :id and :email then an array is passed the keys in the array matches the placeholder and is bound, so the database will get both the query and the bound data.

Data returned from the query will be returns as an object this can be changed by passing a third param to the select containing PDO::FETCH\_ASSOC.

To use the object loop through it, a typical example:

```
$rows = $db->select("firstName, lastName FROM members ORDER BY firstName, lastName");
foreach ($rows as $row) {
    echo "$row->firstName $row->lastName";
}
```

Raw
===

[](#raw)

A raw query is a query that is not ran through a prepared statement and will execute the query passed directly. Useful when creating a table.

```
$db->raw("CREATE TABLE IF NOT EXISTS members (
  memberID INT(11) NOT NULL AUTO_INCREMENT,
  firstName VARCHAR(255) NOT NULL,
  lastnName VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  PRIMARY KEY (memberID))"
);
```

Insert
------

[](#insert)

Data is inserted by calling the insert method it expects the table name followed by an array of key and values to insert in to the database.

```
$data = array(
    'firstName' => 'Joe',
    'lastnName' => 'Smith',
    'email' => 'someone@domain.com'
);
$db->insert('members', $data);
```

The insert automatically returns the last inserted id by returning 'lastInsertId' to collect the id:

```
$id = $db->insert('members', $data);
```

Updating
--------

[](#updating)

To update an existing record the update method is called. This method expects the table, array of data to update and a second array containing the where condition.

```
$data = array(
    'firstName' => 'Joe',
    'lastnName' => 'Smith',
    'email' => 'someone@domain.com'
);
$where = array('memberID' => 2);
$db->update('members', $data, $where);
```

Delete
------

[](#delete)

To delete records call the delete method. This method expects the table name and an array of the where condition.

```
$where = array('memberID' => 2);
$db->delect('members', $where);
```

This will delete a single record to set the limit pass a third parameters containing the number to limit to, or to remove the limit pass null as a third param.

```
$db->delete('members', $where, 10);  //delete 10 records matcing the where
$db->delete('members', $where, null); //delete all records matching the where

## Truncate

To empty a table of all contents call the truncate method. Passing only the table name.

````php
$db->truncate('members');
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29592430?v=4)[Daniel Wyrzykowski](/maintainers/kovsky0)[@kovsky0](https://github.com/kovsky0)

---

Top Contributors

[![daveismynamecom](https://avatars.githubusercontent.com/u/60222583?v=4)](https://github.com/daveismynamecom "daveismynamecom (5 commits)")[![kovsky0](https://avatars.githubusercontent.com/u/29592430?v=4)](https://github.com/kovsky0 "kovsky0 (2 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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