PHPackages                             celiovmjr/simplequery - 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. celiovmjr/simplequery

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

celiovmjr/simplequery
=====================

Streamlined SQL Queries Made Simple

1.2.0(1y ago)0133MITPHPPHP &gt;=8.1

Since Jun 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/celiovmjr/SimpleQuery)[ Packagist](https://packagist.org/packages/celiovmjr/simplequery)[ RSS](/packages/celiovmjr-simplequery/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (2)Versions (19)Used By (0)

SimpleQuery
===========

[](#simplequery)

A PHP class `SimpleQuery` designed for building SQL queries and interacting with a database using PDO.

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
    - [Creating an Instance](#creating-an-instance)
    - [Setting and Getting Data](#setting-and-getting-data)
    - [Executing Queries](#executing-queries)
    - [CRUD Operations](#crud-operations)
- [Contributing](#contributing)
- [License](#license)

Introduction
------------

[](#introduction)

The `SimpleQuery` class provides a fluent interface for constructing SQL queries dynamically. It supports basic CRUD operations (Create, Read, Update, Delete) and facilitates parameter binding, making database interactions secure and efficient.

Features
--------

[](#features)

- Fluent interface for building SQL SELECT, INSERT, UPDATE, and DELETE queries.
- Parameter binding to prevent SQL injection attacks.
- Supports fetching results as arrays or objects.
- Easy setup and integration with existing PDO connections.
- Handles table joins, WHERE conditions, ORDER BY clauses, LIMIT, and OFFSET.

Installation
------------

[](#installation)

To use the `SimpleQuery` class, ensure you have PHP 8.1+ and PDO extension installed. Simply include or autoload the class file in your project:

```
composer require celiovmjr/simplequery;

```

Usage
-----

[](#usage)

### Creating an Instance

[](#creating-an-instance)

Create a new instance of `SimpleQuery` by passing an initialized PDO connection:

```
use Builder\Application\SimpleQuery;

// Assuming $connection is your PDO connection
class User extends SimpleQuery
{
    protected string $table = 'users'; // Ignore if your table name is the same as the class (plural form)
    protected string $primaryKey = 'id'; // Ignore if your primary key is 'id'
    protected array $required = ['name', 'username', 'email', 'sector']; // Required fields
    protected array $safe = []; // Typically fields with default values

    public function __construct()
    {
        parent::__construct($connection);
    }
}

$user = new User();
```

### Setting and Getting Data

[](#setting-and-getting-data)

You can set data to be used in queries using magic methods (`__set`, `__get`, `__isset`, `__unset`), array conversion methods (`fromArray`, `toArray`), or object conversion methods (`fromObject`, `toObject`):

```
$user->fromArray(['name' => 'John Doe', 'age' => 30]);
```

### Executing Queries

[](#executing-queries)

Build and execute queries using fluent methods:

```
$results = $user->select()->where('age > :age', ['age' => 25])->fetch(true);
```

### CRUD Operations

[](#crud-operations)

Perform CRUD operations easily:

```
// Create
$user->fromArray([
    'name' => 'Jane Doe',
    'age' => 28
]);
$user->save();

// Read
$user->select()->where('id = :id', ['id' => 1])->fetch();

// Update
$user->name = 'New Name';
$user->save();

// Delete
$user->delete(1);
```

Contributing
------------

[](#contributing)

Contributions are welcome! Feel free to open issues or pull requests for any improvements or fixes.

License
-------

[](#license)

This project is licensed under the MIT License - see the LICENSE file for details.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

18

Last Release

694d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58183571?v=4)[Célio Junior](/maintainers/celiovmjr)[@celiovmjr](https://github.com/celiovmjr)

---

Top Contributors

[![celiovmjr](https://avatars.githubusercontent.com/u/58183571?v=4)](https://github.com/celiovmjr "celiovmjr (20 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/celiovmjr-simplequery/health.svg)

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

###  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)
