[英]Codeigniter Active Record SQL syntax error
I have the following Active Record pattern within one of my models : 我的一个模型中有以下Active Record模式:
$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');
我不知道为什么我的表names
没有显示,因为我正在调用$this->db->get('names');
which should produce SELECT * FROM names
, is it just not returning in the error? 哪个应该生成SELECT * FROM names
,它是不是在错误中返回? What's wrong with this statement and what should I do to correct my Active Record call? 这句话有什么问题,我应该怎么做才能纠正我的Active Record电话?
get
needs to go at the end. get
需求。 If you want to select a table before - use $this->db->from('names');
如果你想在之前选择一个表 - 使用$this->db->from('names');
and then just $this->db->get();
然后只需$this->db->get();
. 。 So the full code: 那么完整的代码:
$this->db->like('name', $name);
$this->db->where('ratio >=', 0.75);
$this->db->order_by('ratio', 'desc');
$query = $this->db->get('names');
or the chaining version: 或链接版本:
$query = $this->db->like('name', $name)
->where('ratio >=', 0.75)
->order_by('ratio', 'desc')
->get('names');
Using from
: 使用from
:
$query = $this->db->from('names')
->like('name', $name)
->where('ratio >=', 0.75)
->order_by('ratio', 'desc')
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.