Recommend this page to a friend! |
![]() ![]() |
Info | ![]() |
![]() |
![]() ![]() |
Reputation | Support forum | Blog (1) | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 126 | All time: 9,358 This week: 114![]() |
Version | License | PHP version | Categories | |||
php-search-controlle 1.4 | GNU General Publi... | 5 | PHP 5, Databases, Searching |
PHPSearchController is a simple php class to search mysql database, it can build SQL query to perform MySQL database searches by takeing 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 combine several conditions using SQL operators such as AND, OR, NAND, LIKE NOR & FIND_IN_SET
and return the appropriate queries for the search.
Installation is super-easy via Composer:
composer require peterujah/php-search-controller
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 build the search query like 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 query like example below.
$searchQuery = "PHP Code";
$search->setQuery($searchQuery)->split();
$search->setTags("code_tags");
//var_export($search->getQuery());
Set inital query and pass search query to your mysql connection
$search->setSQLQuery("SELECT * FROM code WHERE id = 1323");
$db->conn()->prepare($search->getAndQuery());
$db->conn()->execute();
$resault = $db->conn()->getAll();
$db->conn()->free();
OR bulid it with other sql query like below in your mysql connection
$db->conn()->prepare("
SELECT * FROM code
{$search->getWhereQuery()}
AND id = 1323
");
$db->conn()->execute();
$resault = $db->conn()->getAll();
$db->conn()->free();
Returns the computed sql search queries by checking if initial query was specified or not to determine which start clause is needed.
$search->getQuery()
Returns the computed search queries by using AND
as the start clause.
$search->getAndQuery()
Returns the computed search queries by using WHERE
as the start clause.
$search->getWhereQuery()
Specify search operator $search->setOperators(SearchController::HAVE_ANY_QUERY)
| Search Operators | Description | |--------------------------|-----------------------------------------------------------------------------------| | START_WITH_QUERY | Finds any values that start with "query" | | END_WITH_QUERY | Finds any values that end with "query" | | HAVE_ANY_QUERY | Finds any values that have "query" in any position | | HAVE_SECOND_QUERY | Finds any values that have "query" in the second position | | START_WITH_QUERY_2LENGTH | Finds any values that start with "query" and are at least 2 characters in length | | START_WITH_QUERY_3LENGTH | Finds any values that start with "query" and are at least 3 characters in length | | START_END_WITH_QUERY | Finds any values that start with "query" and ends with "query" |
Initalise search class with a method new SearchController(SearchController::OR)
| Search Methods | Description | |------------------------|-------------------------------------------------------------------------------------| | OR | Retrieve result with any one of search query | | AND | Retrieve result with the exact of search quer | | NAND | Retrieve result without the exact search query | | NOR | Retrieve result without any on of the search query |
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation |
![]() | php-search-controlle-2022-05-14.zip 4KB |
![]() | php-search-controlle-2022-05-14.tar.gz 4KB |
![]() | Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.