PHPackages                             jek/psm - 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. jek/psm

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

jek/psm
=======

A small yet powerful extra layer of abstraction to native database connections

27PHP

Since May 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/halesyy/psm)[ Packagist](https://packagist.org/packages/jek/psm)[ RSS](/packages/jek-psm/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)DependenciesVersions (1)Used By (0)

PSM
===

[](#psm)

Intro
-----

[](#intro)

PSM is a PDO (PHP Database Objects) re-write, to add another layer of abstraction to your database connections, without slowing performance.

PSM tries to make you think for the quickest and less code-used solutions to your problems, creating easy-to-read statements easily integrated into any environment, from auto-binding queries allowing no SQL-Injection to creating chain functions to build statements then run the outcomse!

Install
-------

[](#install)

PSM3 is defaulted with 3 MAIN files, and an OPTIONAL 4th file. These files are located in the **classes** folder of the project, and the files (*to load in order*) are, **PSMExtra**, **PSMQuery** and **PSMMain**.

There's two ways to go-about creating your PSM3 class instance, you can either connect to a database in the constructor, or create your class instance then later connect. - This was not possible in older versions of PSM. (The third option is for database migration)

**Before starting, make sure you've included your files!**:

```
require_once('classes/PSMExtra.php');
require_once('classes/PSMQuery.php');
require_once('classes/PSMMain.php');
```

### Connecting straight from the constrcutor

[](#connecting-straight-from-the-constrcutor)

```
$psm = new PSM('HOSTNAME DATABASE USERNAME PASSWORD');
// If your password is empty, use the 'EM' keyword in password to emulate an empty space.
$psm->version();
```

### Connecting after creating the instance

[](#connecting-after-creating-the-instance)

```
$psm = new PSM;
$psm->connect('HOSTNAME DATABASE USERNAME PASSWORD');
$psm->version();
```

### Connecting using a capsule

[](#connecting-using-a-capsule)

```
// A capsule is a simple string generated by $psm->capsule() when on a server running PSM.
$psm = new PSM;
// Capsule would be generated from another server.
$capsule = "PSM_DB_CAPSULE{HOSTNAME::DATABASE::USERNAME::PASSWORD}";
$psm->decapsule($capsule);
```

And there you have it! A simple **PSM** connection! Any 3 of these solutions to creating your instance is always going to be quick, and you can easily get your PDO handler simply by using:

```
$pdo = $psm->handler;
```

So, this can always be used as a way to generate PDO handlers.

Documentation
-------------

[](#documentation)

When making a new PSM object, you are given a lot of functions 😏

> **If you don't really know any PHP OOP, I recommend you understand how classes work and functions work together, you can read up on it [here - php manual](http://php.net/manual/en/language.oop5.php) or [here - youtube tutorial](https://www.youtube.com/watch?v=ipp4WPDwwvk&list=PLfdtiltiRHWF0RicJb20da8nECQ1jFvla)**

Create a simple PSM object as we showed you how before, then we can continue!

### How to add a driver

[](#how-to-add-a-driver)

```
$psm = new PSM('localhost test root EM',[
  'safeconnection' => false
]);
```

Drivers are something I've never spent a lot of time using/creating, but would be appreciated if added to a PR.

PSM3 Function Analysis
----------------------

[](#psm3-function-analysis)

FunctionDescriptionversionDisplays the version of the current PSM instance instantiated.qa / helpQuery analysis - Will take in a prepared statement and analyze error messages, and report back.cqueryFirst param is the statement, second param is the binder to the query. Binder is optional if you want a base query.cstatementArray-to-statement generator, example input `['select' => 'users', 'where' => 'id = 1']; ` will create a statement judging from the array inputs.short\_csatementArray-to-statement generator but smaller array, example input `['users','username','id = 1']; ` will create **SELECT username FROM users WHERE id = 1**.statDoes a simple static function, prepares and binds the query, i.e. an **INSERT** statement is static.setTakes in a statement and optional binding to create a query and return the first row in an ASSOCIATIVE array.rowsReturns the row count of the statement and binds supplied to create the query.hasdataShorthand rows function but will check if there's any rows, if so return **true** / **false**.hasnodataOpposite of hasdata.hasdata\_specificTakes in table, column, what the column has to equal to, and callers, looks in table column for specific data, if so will return true or false, if the 4th paramater is supplied, will call a 'true' or 'false' array callback. `['true' => FUNCTION, 'false' => FUNCTION] `query\_rowsRows function but if you have created a query.infoIf you set the first paramater to true, displays all functions in PSM as well as some other inforamtion about the class, if set to false will just show number of functions.get\_colsTakes in a table as it's first paramater, will return the column names of the table.table\_existsReturns bool of true or false if the table is existant in the current database.updateShorthand **UPDATE** statement function, takes in a table as the first paramater and an array as the second, the array needs to contain columns as keys and data as rows, then the third paramater must be a where statement built as a clause following the form of **COLUMN = DATA**, and no other exceptions - Fourth paramater is debug, set to true if you wanna see the statement / binds auto-generated from the function.deleteTakes in first paramater as the table name, if nothing else is given will simply delete the entire table - Second paramater is the column you want to look in, and the selectors as the third paramater, meaning you can run: `$psm->delete('users', 'id' [1,2,3]);` Which will simply delete users with ID's of 1, 2 or 3.get\_column\_dataLooks in a table then the column, then returns a numerative array of all the data in that row, i.e. Get all usernames from the table users.dataTakes in statement and bind as both paramaters, and returns array containing the actual query itself, rowcount, queryset/set, statement and the binds of the query.insertRuns similar to the update function where it performs an insert on the table given in the first paramater, then uses the array keys as columns and values as data, third paramater is debug.capsuleRun to store your current database inforamtion in a string, use to migrate or **capsule your connection for later-use**.decapsuleUses data generated from **capsule** to re-create a connection.### More on capsules (and serializing the PSM variable)

[](#more-on-capsules-and-serializing-the-psm-variable)

#### Seems pretty useless to take a string and put it on another server to act as the serve, right?

[](#seems-pretty-useless-to-take-a-string-and-put-it-on-another-server-to-act-as-the-serve-right)

Well, this wasn't the main aim for building the capsule function, the aim was to be able to store that capsule data to later re-construct the connection, but even now there's an easier way to do that, so I'll show you both ways. (please don't store stuff like database connectors in session, just don't, this is just an example)

```
$_SESSION['psm'] = $psm->capsule();
$psm = false;
// do some stuff over pages
. . .
// oo! we need psm again!
$psm = new PSM;
$psm->decapsule($_SESSION['psm']);
$psm->version();
```

But that's a bit... edgy... So use this way!

```
$psm->close();
$_SESSION['psm'] = $psm;
// do some stuff over pages
. . .
// oo! we need psm again!
$psm = $_SESSION['psm']->open();
$psm->version();
```

That way you're storing your entire class in the variable, even safer!

### Chains

[](#chains)

#### PSM has a nice semi-function-set for chaining, allowing you to create statements that're easily readable quite quickly.

[](#psm-has-a-nice-semi-function-set-for-chaining-allowing-you-to-create-statements-thatre-easily-readable-quite-quickly)

This is the PSM chaining functions at it's first integration, more to come!

```
// SELECT username FROM users WHERE id < ? ORDER BY id DESC LIMIT 2
// (v = DESC, ^ = ASC)
$psm->select(['users','username'])->where('id < 5')->order('v', 'id')->limit(2)->run(function($row){
  print_r($row);
});
```

After the statement is constructed, the rows are looped in the callback function given in **run**, easy!

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18212?v=4)[jason kirtland](/maintainers/jek)[@jek](https://github.com/jek)

---

Top Contributors

[![halesyy](https://avatars.githubusercontent.com/u/13494044?v=4)](https://github.com/halesyy "halesyy (32 commits)")

---

Tags

capsuledatabasedriverjekpdopdo-handlerspsm

### Embed Badge

![Health badge](/badges/jek-psm/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/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)
