How to enable backticks in active mysql codeigniter record

I am trying to activate an active codeigniter account, it gives me an error when I try to update a field named Dec (Jan-Nov was good before) ...

This is my code.

        $this->db->set($month,"$month+$tax", FALSE);
        $this->db->set('total_yearly',"total_yearly+$tax", FALSE);
        $this->db->where(array('tax_category' => $tax_category));
        $this->db->update($nama_table); 

And the request will return like this:

UPDATE `tax` SET Dec = Dec+10000, total_yearly = total_yearly+10000 WHERE `tax_category` = 'Hotel' AND `year` = '2017'

Error message

You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near 'Dec = Dec + 2479, total_yearly = total_yearly + 2479 WHERE tax_category=' Hotel 'AN' on line 1

Any solution? I tried adding backticks to the request, but the result is still the reverse being removed, or maybe I did not do it well.

thank

+4
source share
3 answers

:

$this->db->set($month,"$month+$tax", FALSE);

:

$this->db->set("`$month`","`$month`+$tax", FALSE);

+1

, :

FALSE,

set() ($escape), , FALSE.

$this->db->set($month,$month.'+'.$tax);
$this->db->set('total_yearly',"total_yearly+".$tax);
$this->db->where(array('tax_category' => $tax_category));
$this->db->update($nama_table); 

: https://www.codeigniter.com/user_guide/database/query_builder.html#updating-data

+2

I think the problem is that "DEC" is a reserved word . Throw some backlinks around the field names in the SET clause so the query reads:

UPDATE `tax` SET `Dec` = `Dec`+10000, `total_yearly` = `total_yearly`+10000 WHERE `tax_category` = 'Hotel' AND `year` = '2017'
+1
source

Source: https://habr.com/ru/post/1695788/


All Articles