Welcome Guest, Not a member yet? Register   Sign In
Database error 1064 and charset utf-8
#1

[eluser]royduin[/eluser]
Hi,

I'm getting this error database error: 1064, I've found a "solution" but I think it's not necessary.

The model function:
Code:
function update_favorite($data)
{
$this->db->where('id', $data['id']);
$this->db->where('user_id', $data['user_id']);
$this->db->update('favorites', $data);
return;
}

Call this function from the controler:
Code:
$this->favorites_model->update_favorite(array(
'id' => $id,
'rss_last' => $rss_last,
'user_id' => $this->session->userdata('user_id')
));

When $rss_last is a "normal" value like: "test" (without quotes) it works fine.
When it's a value with more length like (in Dutch): F-Secure vindt malware met certificaat van Maleisische overheid

I get this error:
Quote:Error Number: 1064

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 'vindt malware met certificaat van Maleisische overheid, `user_id` = '1' WHERE `i' at line 1

UPDATE `favorites` SET `id` = '15', `rss_last` = F-Secure vindt malware met certificaat van Maleisische overheid, `user_id` = '1' WHERE `id` = '15' AND `user_id` = '1'

Filename: /home/***/domains/***.nl/public_html/new/models/favorites_model.php

Line Number: 35

When I change the line
Code:
'rss_last' => $rss_last,
To this:
Code:
'rss_last' => $this->db->escape_str($rss_last),
It works fine, but now I have sometimes a ugly backslash in my database.....

What to do?

PS. I thought that CI escapes values automatically when using the Active Record class?




Theme © iAndrew 2016 - Forum software by © MyBB