我正在尝试使用MySQL函数UNHEX()与LIKE操作符一起使用,但是我无法得到期望的结果,即$result_2_expected
。
我做错了什么?
我尝试了以下几种方法,但都没有成功:
- LIKE UNHEX('%4272756365%')
- LIKE '%UNHEX('4272756365')%'
- LIKE '%UNHEX(4272756365)%'
等于操作符的经验(成功):
$name_1 = bin2hex("Bruce Wayne"); //4272756365205761796e65
$query_1 = "SELECT `NAME` FROM `USERS_TABLE` WHERE `NAME` = UNHEX('{$name_1}')"; // UNHEX('4272756365205761796e65')
$result_1 = [0][NAME] => "Bruce Wayne"; // Success
使用 LIKE 运算符的经验(失败):
$name_2 = bin2hex("Bruce"); // 4272756365
$query_2 = "SELECT `NAME` FROM `USERS_TABLE` WHERE `NAME` LIKE UNHEX('%{$name_2}%')"; // UNHEX('%4272756365%')
$result_2 = [] => null; // Fail
$result_2_expected = [0][NAME] => "Bruce Wayne"; [1][NAME] => "Bruce Willis"; [2][NAME] => "Bruce Springsteen"; // Expected as Success