【发布时间】:2015-08-31 06:34:51
【问题描述】:
我正在尝试从 mysql 表中选择一些数据,但我无法让 Where 比较不区分大小写,我尝试使用 LOWER:
$wildcard = $_GET['q'];
$query = "SELECT id, name, departamento FROM gestionDoc_cargos WHERE (LOWER(name) LIKE '%' LOWER(:wildcard) '%' OR LOWER(departamento) LIKE '%' LOWER(:wildcard) '%')";
try{
$result = DB::getInstance()->prepare($query);
$result->bindParam(':wildcard', $wildcard, PDO::PARAM_STR);
$result->execute();
$result = $result->fetchAll(PDO::FETCH_ASSOC);
}catch(PDOException $e){
die($e->getMessage());
}
print_r($result);
echo json_encode(array_values($result));
但我收到以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LOWER('C') '%' OR LOWER(departamento) LIKE '%' LOWER('C') '%')' at line 1
如果我从查询中删除 LOWER,我会得到一个区分大小写的选择。
【问题讨论】: