我想使用 MySQL like
查询从数据库中搜索数据
这是我的查询:
global $wpdb;
if($_GET['search']){
$search = $_GET['search'];
}
else{
$search = $_GET['searchtop'];
}
$search_details = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM
tbl_brand,
tbl_generic,
tbl_therapeutic_area,
tbl_drug
WHERE
tbl_brand.generic_id = tbl_generic.generic_id
AND
tbl_brand.therapeutic_area_id =
tbl_therapeutic_area.therapeutic_area_id
AND
tbl_brand.brand_id = tbl_drug.brand_id
AND
tbl_brand.brand_name LIKE '%$search%'",""
),ARRAY_A
);
我的数据就像数据库中的 DUET
{upper case letter} 我使用小写 duet
搜索它返回 no results found
但是当我搜索 Duet
找到了。
使用 duet
搜索时查看结果
in lower case: duet results
使用 Duet
搜索时查看结果
in Duet: results
如果我在 phpmyadmin 中手动使用此 SQL 查询,则会找到结果。
所以我想使用小写或大写来获取数据!
最佳答案
我正在正确使用准备查询,例如:
$wpdb->prepare(
"SELECT * FROM tbl_brand,tbl_generic,tbl_therapeutic_area,tbl_drug
WHERE tbl_brand.generic_id = tbl_generic.generic_id
AND tbl_brand.therapeutic_area_id = tbl_therapeutic_area.therapeutic_area_id AND tbl_brand.brand_id = tbl_drug.brand_id AND LOWER(tbl_brand.brand_name) LIKE %s",'%' . $wpdb->esc_like($search) . '%',""
),ARRAY_A
及其作品。
关于php - 使用类似 mysql 的查询使用小写或大写获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56864851/