-2
I am using the code below to make a query in the database, but it is giving the following error:
PHP Error was encountered Severity: Notice Message: Undefined Property: Admin::$db Filename: core/Model.php Line Number: 51
Fatal error: Call to a Member Function query() on a non-object in /home/*/public_html/application/models/admin_model.php on line 4**
Code
class Admin_model extends CI_Model {
public function carregar_hoteis(){
$hoteis = $this->db->query("SELECT * FROM tabela");
$array=array();
foreach($hoteis->result() as $row)
{
$array['hoteis'][]=$row;
}
echo json_encode($array);
}
}
By any chance, are you loading the library database? Just for free...
– Marcelo Diniz
Shouldn’t be
$this->db->get
instead of$this->db->query
?– Ricardo
@Ricardo o Codeigniter permite as duas formas. Give a look here: http://ellislab.com/codeigniter/user-guide/database/queries.html
– Marcelo Diniz