如何在 codeigniter 中的 concat 字符串中搜索字符串

How to search string in concat string in codeigniter

这是我的查询

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where('full_name', $customerSearch);
$run_q = $this->db->get('customers');

但是我收到错误消息。

Unknown column 'full_name' in 'where clause'

我怎么了?

请试试这个:

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where(CONCAT(customers.first_name, " ", customers.last_name), $customerSearch);
$run_q = $this->db->get('customers');

您收到错误消息是因为您不能在 'where' 子句中使用 'derived column'(即 full_name)的别名。