[eluser]Unknown[/eluser]
Hey there!
I started using CI a few days ago, so i'm not totally used to it.
Anyway...i'm having some problems with the database. (MySQL) It works fine when i'm not using CI, but when i try to use it, the thing just doesn't work.
I tried to build the DB code in a Controller and then in a Model, and none worked.
This code only outputs the first string, but not the second one.
Code:
class SomeClass extends Controller {
function SomeClass(){
parent::Controller();
}
function index(){
echo "first";
$this->load->database();
echo "second";
}
}
Second example, using SomeClass again:
Code:
function index(){
$this->load->model('somemodel');
}
now, SomeModel:
Code:
class SomeModel extends Model{
function SomeModel(){
parent::Model();
echo "This is from the model.";
$this->load->database();
echo "This is from the model too, but it doesn't work.";
}
}
Same thing happens. It outputs the first string, but not the second.
Code:
class SomeModel extends Model{
function SomeModel(){
parent::Model();
echo "This is from the model.";
$this->db->query('SELECT name, title FROM my_table');
}
}
This outputs the string, and gives an error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: SomeModel::$db
Filename: models/somemodel.php
Line Number: 6
Fatal error: Call to a member function query() on a non-object in C:\Arquivos de programas\EasyPHP 2.0b1\www\ign\system\application\models\somemodel.php on line 6
I even tried to do something like this:
$db = $this->load->database();
but didn't work.
How can i solve this?