0

I have the following Active Record pattern within one of my models :

$this->db->get('names');
$this->db->like('name', $name);
$this->db->where('ratio >=', 0.75);
$this->db->order_by('ratio', 'desc');

$query = $this->db->get();

This gives me a syntax error :

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 'WHERE `ratio` >= 0.75 AND `name` LIKE '%JORDAN%' ORDER BY `ratio' at line 2

The full statement being returned is :

SELECT * WHERE `ratio` >= 0.75 AND `name` LIKE '%JORDAN%' ORDER BY `ratio` desc

I don't know why my table names isn't showing as I'm calling $this->db->get('names'); which should produce SELECT * FROM names, is it just not returning in the error? What's wrong with this statement and what should I do to correct my Active Record call?

4

1 回答 1

2

get最后需要去。如果你想在使用前选择一个表$this->db->from('names');然后就可以了$this->db->get();。所以完整的代码:

$this->db->like('name', $name);
$this->db->where('ratio >=', 0.75);
$this->db->order_by('ratio', 'desc');
$query = $this->db->get('names');

或链接版本:

$query = $this->db->like('name', $name)
->where('ratio >=', 0.75)
->order_by('ratio', 'desc')
->get('names');

使用from

$query = $this->db->from('names')
->like('name', $name)
->where('ratio >=', 0.75)
->order_by('ratio', 'desc')
->get();
于 2013-06-15T18:03:03.420 回答