Fork me on GitHub


A tiny PHP tool for generating SQL wildcard PDO prepared statements for RDBMS.

When utilizing something like enhanced 'for' or 'foreach' loops to iterate through arrays of multiple user submitted inputs prepped for an SQL wildcard database search, the length of the PDO prepared statement must change. This can prove a tedious task. Gumshoe.php is a dynamic tool that automates the process, and generates a prepared statement as well as its final input argument array.


Download package files from Github.


Include the Gumshoe.php file in your document:

include 'path/to/Gumshoe.php';

You can also autoload the Gumshoe class:

	include 'gumshoe_dir/Gumshoe.php'			


Create a new Gumshoe instance. Gumshoe instances require two arguments:

1) The name of the table from which your prepared statement will be retrieving data. This must be a string.
2) The column names in the aforementioned table in which you will match the statement's wildcards. This must be an array type:

$gumshoe = new Gumshoe('myTable',['column1','column2','column3']);

Use the 'search' method to enter the strings you are searching for. The search method takes one array as an argument:


Retrieve the completed prepared statement with the 'statement' method:


Retrieve the completed input array for the prepared statement with the 'args' method:


An Example:

$gumshoe = new Gumshoe('myTable',['myColumn']);
$gumshoe->statement();  // SELECT * FROM myTable WHERE myColumn LIKE ? OR myColumn LIKE ?
$gumshoe->args();  // [%search%,%me%]

The statement can be prepared and its arguments executed:

$stmt = $this->pdo->prepare($gumshoe->statement());


Gumshoe.php is compatible with any server that supports PHP 5.6+ and most relational databases.


Licensed under the MIT License.

Copyright © 2017 Li George