Archive for the ‘Uncategorized’ category


How to bind PHP variable in SQL LIKE statement

This is very useful when you are writing an application which does search in a ORACLE/SQL database.

$searchterm='xyz';

Now use above variable to ‘searchterm’ to find any product which name has ‘xyz’ string, irrespective whatever is preceding to xyz or trailing to xyz.

SELECT Product_Number, Product_Name, Product_Description  FROM `productDetails`
where Product_Name like '%".$searchterm."%'

Here is Wild-card list recognize by SQL server and Oracle. I have used ‘%’ for above demo

Wildcard Searches for
% Any string of zero or more characters.
_ Any single character.
[ ] Any single character within the specified range (for example, [a-f]) or the specified set (for example, [abcdef]).
[^] Any single character not within the specified range (for example, [^a-f]) or the specified set (for example, [^abcdef]).

For oracle variable you can use @searchterm.