Codeigniter 2.1 - MySQL CONCAT (append string)

2019-09-19 07:58发布

问题:

I have PHP code like this:

$query = 'UPDATE  `user_vote` SET `container` = CONCAT(`container`, ' ;
$query .=  ",$glas";
$query .= ') WHERE `user_id` = ' . $id_u;
$this->db->query($query);

When I run this code, I got following error:

Error Number: 1054

Unknown column ',iljadu' in 'field list'

UPDATE user_vote SET container = CONCAT(container, ,iljadu) WHERE user_id = 4

What is wrong with the query?

回答1:

You are missing quotes around your variable for the concat()

$query = 'UPDATE  `user_vote` SET `container` = CONCAT(`container`, ' ;
$query .=  ",'$glas'";
$query .= ') WHERE `user_id` = ' . $id_u;
$this->db->query($query);


回答2:

$query .=  ",$glas";

should be

$query .=  "$glas";