将变量传递到mysql所在的位置

时间:2017-12-19 16:17:20

标签: php mysql pdo mysql-variables

无法让查询运行,在@searchin变量上抛出错误。 可能很简单但看不到它。

set @search = "chip";
set @searchin = "CompanyName";

select * from con_search where @searchin like concat ('%',@search,'%')

1 个答案:

答案 0 :(得分:0)

这样可行,但是你应该对进入它的数据进行整理

set @search = 'chip';
set @searchin = 'CompanyName';
set @SQL = CONCAT("SELECT * FROM con_search WHERE `", @searchin, "` LIKE CONCAT('%'", @search, "'%');";
PREPARE stmt1 FROM @SQL;
EXECUTE stmt1;