{"id":26796457,"url":"https://github.com/peterujah/php-search-controller","last_synced_at":"2025-04-22T19:57:55.685Z","repository":{"id":57038189,"uuid":"437862685","full_name":"peterujah/php-search-controller","owner":"peterujah","description":"\"Php advance search class for mysql database.","archived":false,"fork":false,"pushed_at":"2024-06-05T00:48:31.000Z","size":47,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T18:18:38.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/peterujah/PHPSearchController","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterujah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-12-13T12:23:37.000Z","updated_at":"2024-06-05T00:48:04.000Z","dependencies_parsed_at":"2023-02-08T20:35:12.367Z","dependency_job_id":"7a4605d0-3095-4a15-a7d4-165722f1c0aa","html_url":"https://github.com/peterujah/php-search-controller","commit_stats":{"total_commits":47,"total_committers":1,"mean_commits":47.0,"dds":0.0,"last_synced_commit":"cd648db806067a5504e61bf42f59b94984feca37"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-search-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-search-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-search-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterujah%2Fphp-search-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterujah","download_url":"https://codeload.github.com/peterujah/php-search-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250315961,"owners_count":21410473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-29T18:18:44.474Z","updated_at":"2025-04-22T19:57:55.662Z","avatar_url":"https://github.com/peterujah.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPSearchController\n\nPHPSearchController 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.\n\nThe 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 \u0026 FIND_IN_SET` and return the appropriate queries for the search.\n\n## Installation\n\nInstallation is super-easy via Composer:\n```md\ncomposer require peterujah/php-search-controller\n```\n\n# Usages\n\nInitialize the class with your preferred search method the default method is `SearchController::OR`.\n```php \nuse Peterujah\\NanoBlock\\SearchController;\n$search = new SearchController();\n```\n\n\nSet your preferred search operator the default is `SearchController::END_WITH_QUERY`.\n```php\n$search-\u003esetOperators(SearchController::HAVE_ANY_QUERY);\n```\n\nTo perform a database search, you can just build your search query like the one below.\n\n```php \n$searchQuery = \"PHP Code\";\n$search-\u003esetQuery($searchQuery)-\u003esplit();\n$search-\u003esetParameter(array(\n    'code_title', \n    'code_description', \n    'code_info'\n));\n//var_export($search-\u003egetQuery());\n```\n\nTo search by tag using MySQL `FIND_IN_SET`, build a query like the example below.\n\n```php \n$searchQuery = \"PHP Code\";\n$search-\u003esetQuery($searchQuery)-\u003esplit();\n$search-\u003esetTags(\"code_tags\");\n//var_export($search-\u003egetQuery());\n```\n\nSet the initial query and pass the search query to your MySQL connection\n\n```php \n$search-\u003esetIniQuery(\"SELECT * FROM code WHERE id = 1323\");\n$db-\u003econn()-\u003eprepare($search-\u003egetQuery());\n$db-\u003econn()-\u003eexecute();\t\t\n$result = $db-\u003econn()-\u003egetAll();\n$db-\u003econn()-\u003efree();\n```\n\nOR build it with other sql queries like the below in your MySQL connection\n```php \n$db-\u003econn()-\u003eprepare(\"\n    SELECT * FROM code \n    {$search-\u003egetQuery()}\n    AND id = 1323\n\");\n$db-\u003econn()-\u003eexecute();\t\t\n$result = $db-\u003econn()-\u003egetAll();\n$db-\u003econn()-\u003efree();\n```\n\n# Other Methods\n\nReturns the computed sql search queries by checking if the initial query was specified or not to determine which start clause is needed.\n```php\n$search-\u003egetQuery()\n```\n\nSet your search keyword \n\n```php\n$search-\u003esetQuery(\"Foo Bar\")\n```\n\nSplit search keyword `Foo Bar` into `Foo`, `Bar` as separate search terms\n```php\n$search-\u003esplit()\n```\n\nMapping your database column keys to perform a search on\n\n```php\n$search-\u003esetParameter(array)\n```\n\n\nSet the initial SQL query before appending the search after your query string \n\n```php\n$search-\u003esetIniQuery('SELECT * FROM ...')\n```\n\n# Reference\n\nSpecify search operator `$search-\u003esetOperators(SearchController::HAVE_ANY_QUERY)`\n\n| Search Operators         | Description                                                                       |\n|--------------------------|-----------------------------------------------------------------------------------|\n| START_WITH_QUERY         | Finds any values that start with \"query\"                                          |\n| END_WITH_QUERY           | Finds any values that end with \"query\"                                            |\n| HAVE_ANY_QUERY           | Finds any values that have \"query\" in any position                                |\n| HAVE_SECOND_QUERY        | Finds any values that have \"query\" in the second position                         |\n| START_WITH_QUERY_2LENGTH | Finds any values that start with \"query\" and are at least 2 characters in length  |\n| START_WITH_QUERY_3LENGTH | Finds any values that start with \"query\" and are at least 3 characters in length  |\n| START_END_WITH_QUERY     | Finds any values that start with \"query\" and ends with \"query\"                    |\n\n\nInitialize search class with a method `new SearchController(SearchController::OR)`\n\n| Search Methods         | Description                                                                         |\n|------------------------|-------------------------------------------------------------------------------------|\n| OR                     | Retrieve result with any one of search query                                        |\n| AND                    | Retrieve result with the exact of search quer                                       |\n| NAND                   | Retrieve result without the exact search query                                      |\n| NOR                    | Retrieve result without any on of the search query                                  |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-search-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterujah%2Fphp-search-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterujah%2Fphp-search-controller/lists"}