Page 1 of 1

case sensitive query?

Posted: Mon Jul 13, 2009 5:41 pm
by noclist
I'm pulling records from a database with these 2 queries:

Code: Select all

$stud=$_POST['stud'];
$stud=mysql_real_escape_string($stud);
 
if ($_POST['stud']!="")
{
 
$sql="SELECT * FROM movies WHERE studio like  '%" . $stud . "%'";
and

Code: Select all

$dir=$_POST['dir'];
$dir=mysql_real_escape_string($dir);
 
if ($_POST['dir']!="")
{
 
$sql="SELECT * FROM movies WHERE director like  '%" . $dir . "%'";
However, the search variable I am using in the first query($stud) seems to be case sensitive while $dir is not.
For example, if I want to find all movies by the studio Warner Brothers, searching for 'warner' returns no results. But at the same time searching for 'scorsese' in my director search will return results of Martin Scorsese.

Is there anyway to explain this? The code of both are identical minus the variable name. Thanks in advance if you have any advice.

Re: case sensitive query?

Posted: Mon Jul 13, 2009 5:44 pm
by Skara
http://dev.mysql.com/doc/refman/5.0/en/ ... ivity.html
Does all of that answer your question?

Re: case sensitive query?

Posted: Mon Jul 13, 2009 6:50 pm
by noclist
No, could you sum it up in laymens terms for me?

Does it explain how one of my variables is treated as case sensitive and the other not? They're both just text characters and treated identically in my database and code.

Re: case sensitive query?

Posted: Mon Jul 13, 2009 6:59 pm
by jackpf
Unless they're different data types then I doubt that's the case.

However, if you want it to be case sensitive then you can put BINARY before the column names, if not, run LOWER() on them both.

Re: case sensitive query?

Posted: Mon Jul 13, 2009 7:23 pm
by noclist
Thanks, how would i go about running lower? I would like both searches to be case insensitive. A google search for the lower() function didn't return anything useful for me.

Re: case sensitive query?

Posted: Tue Jul 14, 2009 3:21 am
by jackpf