Click to upgrade request in codeigniter

I have a request = SELECT @condi:=id FROM table WHERE id>1 LIMIT 1 for UPDATE; UPDATE table set aa="ok" WHERE id=@condi

I used $this->db->query(query)

but codeigniter error information "You have an error in your SQL syntax, check the manual corresponding to your MySQL server version for the correct syntax to use next to" update table set "aa =" ok "where id = @condi ' on line 1 "Miss"; " I am using phpmyadmin doing this query it returns the string correctly and not an error request

maybe main code error, can you help me fulfill my request in codeigniter, thanks

+3


source to share


1 answer


You can try to use the Query Builder to prevent the SQL error:

$query = $this->db->select()
            ->from('table')
            ->where('id >', 1)
            ->limit(1)
            ->get_compiled_select();
$data = $this->db->query("{$query} FOR UPDATE")->row_array();

$this->db->where('id', $condi)->update('table', ['aa'=>'ok']);

      



Since the Codeigniter 3 builder doesn't support FOR UPDATE

, so I just use the compiler to reconstruct the request.

Codeigniter get_compiled_select ()

yidas / codeigniter-model - Pessimistic lock

+2


source







All Articles