Reputation: 42350
I have the following code, and I cannot figure out why CodeIgniter is adding an additional wildcard to the query it generates.
Code
class Foo_Model extends CI_Model {
private $table = 'foo';
public function get_all_foos() {
$table = $this->table;
$this->db->select("$table.*")->from($table);
return $this->get()->result();
}
}
And I get the following Error:
A Database Error Occurred
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 '* FROM (
foo
,foo
)' at line 1SELECT
foo
.*, * FROM (foo
,foo
)
Why is there query generating incorrectly?
Upvotes: 0
Views: 457
Reputation: 2211
If you want to select everything, the fastest way to do it is by using get()
directly with table name.
for example:
class Foo_Model extends CI_Model {
private $table = 'foo';
public function get_all_foos() {
$table = $this->table;
return $this->db->get($table)->result();
}
}
Upvotes: 0
Reputation: 3259
I think this is a bug of Codeigniter 2.1.2
This should work for you:
$this->db->select("`$table`.*",false)->from($table);
Upvotes: 0
Reputation: 19294
If you want to select everything, don't use the ->select()
statement. This should be equivalent to what your expected.
class Foo_Model extends CI_Model {
private $table = 'foo';
public function get_all_foos() {
$table = $this->table;
$this->db->from($table);
return $this->get()->result();
}
}
See $this->db->get
from the documentation for an example - http://codeigniter.com/user_guide/database/active_record.html.
Upvotes: 2