I am trying to check a mysqli table field if it is = an exact string.
Namely:
$consulta = "SELECT count(*) as total FROM productos WHERE productos.stock = 'si' ";
Is it well formulated?
I am trying to check a mysqli table field if it is = an exact string.
Namely:
$consulta = "SELECT count(*) as total FROM productos WHERE productos.stock = 'si' ";
Is it well formulated?
It depends on how your column is:
- If the column
stock
is case insensitive (ci)The query:
It will count in the columns whose values are:
- If the column
stock
is NOT case insensitive (ci)It will only count when the value is:
It won't even tell you if the value is:
SI
orSi
orsI
.proof of concept
Let's do some tests with code.
VER FIDDLE
1.
COLLATE
with case insensitive (ci) in theCREATE TABLE
:Departure:
2.
COLLATE
case sensitive (cs) in theCREATE TABLE
The same data as above is used.
Departure:
3.
COLLATE
from the default table, and a column withcs
explicitlyThe
COLLATE
can be set for the whole table, but some columns can have theirCOLLATE
own, different from the table.Test ( case insensitive column ):
Result:
Test ( case sensitive column ):
Result: