PHPackages                             peterujah/php-search-controller - 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. [Search &amp; Filtering](/categories/search)
4. /
5. peterujah/php-search-controller

ActiveLibrary[Search &amp; Filtering](/categories/search)

peterujah/php-search-controller
===============================

Php advance mysql database search to perform search operations.

1.8(1y ago)447MITPHPPHP ^7.0 || ^8.0

Since Dec 14Pushed 1y ago2 watchersCompare

[ Source](https://github.com/peterujah/php-search-controller)[ Packagist](https://packagist.org/packages/peterujah/php-search-controller)[ RSS](/packages/peterujah-php-search-controller/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)DependenciesVersions (8)Used By (0)

PHPSearchController
===================

[](#phpsearchcontroller)

PHPSearchController is a simple PHP class to search MySQL database, it can build SQL queries to perform MySQL database searches by taking parameters that define database table fields and field values to search.

The class generates SQL conditions used to build SQL queries to perform database searches for records that match the criteria based on the table fields and field values defined by the parameters, It then combines several conditions using SQL operators such as `AND, OR, NAND, LIKE NOR & FIND_IN_SET` and return the appropriate queries for the search.

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

[](#installation)

Installation is super-easy via Composer:

```
composer require peterujah/php-search-controller
```

Usages
======

[](#usages)

Initialize the class with your preferred search method the default method is `SearchController::OR`.

```
use Peterujah\NanoBlock\SearchController;
$search = new SearchController();
```

Set your preferred search operator the default is `SearchController::END_WITH_QUERY`.

```
$search->setOperators(SearchController::HAVE_ANY_QUERY);
```

To perform a database search, you can just build your search query like the one below.

```
$searchQuery = "PHP Code";
$search->setQuery($searchQuery)->split();
$search->setParameter(array(
    'code_title',
    'code_description',
    'code_info'
));
//var_export($search->getQuery());
```

To search by tag using MySQL `FIND_IN_SET`, build a query like the example below.

```
$searchQuery = "PHP Code";
$search->setQuery($searchQuery)->split();
$search->setTags("code_tags");
//var_export($search->getQuery());
```

Set the initial query and pass the search query to your MySQL connection

```
$search->setIniQuery("SELECT * FROM code WHERE id = 1323");
$db->conn()->prepare($search->getQuery());
$db->conn()->execute();
$result = $db->conn()->getAll();
$db->conn()->free();
```

OR build it with other sql queries like the below in your MySQL connection

```
$db->conn()->prepare("
    SELECT * FROM code
    {$search->getQuery()}
    AND id = 1323
");
$db->conn()->execute();
$result = $db->conn()->getAll();
$db->conn()->free();
```

Other Methods
=============

[](#other-methods)

Returns the computed sql search queries by checking if the initial query was specified or not to determine which start clause is needed.

```
$search->getQuery()
```

Set your search keyword

```
$search->setQuery("Foo Bar")
```

Split search keyword `Foo Bar` into `Foo`, `Bar` as separate search terms

```
$search->split()
```

Mapping your database column keys to perform a search on

```
$search->setParameter(array)
```

Set the initial SQL query before appending the search after your query string

```
$search->setIniQuery('SELECT * FROM ...')
```

Reference
=========

[](#reference)

Specify search operator `$search->setOperators(SearchController::HAVE_ANY_QUERY)`

Search OperatorsDescriptionSTART\_WITH\_QUERYFinds any values that start with "query"END\_WITH\_QUERYFinds any values that end with "query"HAVE\_ANY\_QUERYFinds any values that have "query" in any positionHAVE\_SECOND\_QUERYFinds any values that have "query" in the second positionSTART\_WITH\_QUERY\_2LENGTHFinds any values that start with "query" and are at least 2 characters in lengthSTART\_WITH\_QUERY\_3LENGTHFinds any values that start with "query" and are at least 3 characters in lengthSTART\_END\_WITH\_QUERYFinds any values that start with "query" and ends with "query"Initialize search class with a method `new SearchController(SearchController::OR)`

Search MethodsDescriptionORRetrieve result with any one of search queryANDRetrieve result with the exact of search querNANDRetrieve result without the exact search queryNORRetrieve result without any on of the search query

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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

Recently: every ~188 days

Total

7

Last Release

713d ago

Major Versions

0.1 → 1.32022-05-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce34af529a4ed50696211a2b4d330fbadd2d1738bc5d010523eb4a85cf342b17?d=identicon)[peterujah](/maintainers/peterujah)

---

Top Contributors

[![peterujah](https://avatars.githubusercontent.com/u/16369609?v=4)](https://github.com/peterujah "peterujah (48 commits)")

---

Tags

phpsearchlibrarymysql searchphp searchsql searchadvance searchsearch classphp search classmysql query

### Embed Badge

![Health badge](/badges/peterujah-php-search-controller/health.svg)

```
[![Health](https://phpackages.com/badges/peterujah-php-search-controller/health.svg)](https://phpackages.com/packages/peterujah-php-search-controller)
```

###  Alternatives

[centamiv/vektor

A native PHP Vector Database implementation with strict binary storage and Zero-RAM overhead.

3418.5k2](/packages/centamiv-vektor)[omaressaouaf/query-builder-criteria

Define reusable query criteria for filtering, sorting, search, field selection, and includes in Laravel Eloquent models

282.4k](/packages/omaressaouaf-query-builder-criteria)[apicart/fql

Filter Query Language

1110.6k](/packages/apicart-fql)

PHPackages © 2026

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