user3192318
user3192318

Reputation:

Are MySQL SELECT queries case-insensitive?

I have a form with method post, users will filter results by brand date etc. If the brand name in the MySQL is stored with non lowercase example ( samsung ) and the search input field is filled with uppercase example ( SAMSUNG ) will it still give me the correct results or will cause errors ?

$branded=mysqli_real_escape_string($db, $_GET['brand']); // USER TYPED SAMSUNG
}
$query= "SELECT * FROM `brands` WHERE `brand` = '$branded' LIMIT 1"; // stored as samsung

Upvotes: 1

Views: 1927

Answers (2)

user3192318
user3192318

Reputation:

The locale is "latin1_swedish_ci".

Because it ends in "ci", it must be case-insensitive.

Upvotes: 1

mgrenier
mgrenier

Reputation: 1447

Most MySQL collations are case-insensitive, unless you are doing a binary comparison. In your query case shouldn't change anything. However the following query would mark "samsung" and "SAMSUNG" as different:

$branded=mysqli_real_escape_string($db, $_GET['brand']); // USER TYPED SAMSUNG
}
$query= "SELECT * FROM `brands` WHERE BINARY `brand` = '$branded' LIMIT 1"; // stored as samsung

You would have to check your collation to know for sure whether it is case-sensitive but the easiest way would just be to test it.

Use this link as a reference:

http://dev.mysql.com/doc/refman/5.0/en/charset-binary-op.html

Upvotes: 1

Related Questions