gpt4 book ai didi

php - 将列合并为一列mysql

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:17 26 4
gpt4 key购买 nike

我想将两列合并为一列作为全名,为此我编写了以下代码:

    $this->db->select('CONCAT(first_name," ",last_name) AS FullName');
$this->db->from('customer');
$this->db->where('user_id',1);
$query = $this->db->get();
return $query->result_array();

结果查询将是:

SELECT CONCAT(first_name," ",last_name) AS FullName 
FROM customer
WHERE user_id = 1

但是当我执行上面的代码时,它给了我:

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 'FROM (customer) WHERE user_id = '1' at line 2

我也尝试过 concat_ws group_concat 但无法正常工作。谁能看出我做错了什么?

最佳答案

默认情况下,CI 会尝试转义您传递给 db->select() 的内容(以防您传递用户生成的值)。您可以通过将 false 作为第二个参数传递来禁用此功能。

$this->db->select('CONCAT(first_name," ",last_name) AS FullName', false);

关于php - 将列合并为一列mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21561648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com