将变量传递到 mysql
pass variable into where mysql
无法获得对 运行 的查询,在 @searchin
变量上抛出错误。
可能很简单但是看不到。
set @search = "chip";
set @searchin = "CompanyName";
select * from con_search where @searchin like concat ('%',@search,'%')
这会起作用,但是您应该清理进入其中的数据
set @search = 'chip';
set @searchin = 'CompanyName';
set @SQL = CONCAT("SELECT * FROM con_search WHERE `", @searchin, "` LIKE CONCAT('%'", @search, "'%');";
PREPARE stmt1 FROM @SQL;
EXECUTE stmt1;
无法获得对 运行 的查询,在 @searchin
变量上抛出错误。
可能很简单但是看不到。
set @search = "chip";
set @searchin = "CompanyName";
select * from con_search where @searchin like concat ('%',@search,'%')
这会起作用,但是您应该清理进入其中的数据
set @search = 'chip';
set @searchin = 'CompanyName';
set @SQL = CONCAT("SELECT * FROM con_search WHERE `", @searchin, "` LIKE CONCAT('%'", @search, "'%');";
PREPARE stmt1 FROM @SQL;
EXECUTE stmt1;