像这样的东西:
SELECT IFNULL(v.col1 LIKE CONCAT('%','$userInput','%'),0) AS col1_match
, IFNULL(v.col2 LIKE CONCAT('%','$userInput','%'),0) AS col2_match
, IFNULL(v.col3 LIKE CONCAT('%','$userInput','%'),0) AS col3_match
, IFNULL(v.col4 LIKE CONCAT('%','$userInput','%'),0) AS col4_match
, v.*
FROM vw_clients v
WHERE v.col1 LIKE CONCAT('%','$userInput','%') = 1
OR v.col2 LIKE CONCAT('%','$userInput','%') = 1
OR v.col3 LIKE CONCAT('%','$userInput','%') = 1
OR v.col4 LIKE CONCAT('%','$userInput','%') = 1
注意这个结构容易受到 SQL 注入的影响;它取决于$userInput
不包含 SQL 构造。例如
$userInput = "foo')=1 OR '1' LIKE CONCAT('1";