Tags
PHP , MySQL
Asked 8 years ago
4 Oct 2016
Views 1131
debugger

debugger posted

= operator with comparision in mysql ,means not exact match

more explanation :

$terms=array("debug ","data ","secuirty ")//search term , entered with trailing spaces
foreach($terms as $term){
print_r(mysql_fetch_assoc(mysql_query("select count(*) terms where `title`=$term")));

}


i have database table with name of "terms" and it have "debug" title , still it matching with traling space and give me "1" record for
so it should exact matche with '=' operator but it matching with same value with trailing spaces.
'debug'='debug ' -> postive
how can i get exact match for trailing spaced string in mysql with '=' or without '=' ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

if you looking for exact match with case sensitive than STRCMP() function in mysql is good

'like' operator in mysql dont do case sensitive match

select 'debug' like 'Debug' -> give 1
select STRCMP('debug','Debug') -> give 0

so STRCMP() function is good for exact match
Mahesh Radadiya

Mahesh Radadiya
answered Nov 30 '-1 00:00

use like operator instead of "=" for exact match

select 'debug'= 'debug ' -->give 1 // not matching exact with trailing spaces
select 'debug' like 'debug ' -> give 0 //matching exact with trailing spaces

so use 'like' operator instead '=' operator
Post Answer