NK wrote:
Hi all,
Does anyone know of how I can disable case sensitivity for the LIKE
function in SQL?
Currently the SQL statement looks like:
$query = "SELECT * FROM itrader_games WHERE console='$console' AND
genre='$genre' AND title LIKE '%$title%' ";
Most RMBMSs have a built-in function to change case, for instance
"ucase()" and php cirtainly has this function.
So ou can do
$query = "SELECT * FROM itrader_games WHERE console='".$console."' AND
genre='".$genre."' AND ucase(title) LIKE '%".strtoupper($title)."%' ";
do yourself a favour, always put variable references outside string
literals. Variables are much easier to spot and you can have a
consistent approach to evaluating dynamic bits.
a word of warning, the internal database ucase() statement will cause
the RDBMS to have to run this function for each record prior to
evaluation. So there will be the associated performance hit.
In cases where this is a problem, you can create a redundant column that
is maintained [with rules] containing duplicate but uppercased values
which can be searched without the need to run this function.
Of course, we've no idea what database you are using so no one can
really help you there. I imagine some systems may have a setting
somewhere to set case-insensitivity globally, but we don't know what
database system you are running. We also have no idea what the name of
the uppercasing function may be becuase you haven't told us the name of
the database you are using...