[eluser]krankmelder[/eluser]
Hello everybody,
I know, that the problem with database connectivity has been discussed several times ago. But I spent half a day on checking every solution and going through the forum topics.
I am using Codeigniter 2.1.2 on a Windows machine with Apache and PHP 5 and MySQL (newest XAMPP)
Well problem is, that I cannot get the database connectivity for the models. In the controller however it works fine. Therfore a little example:
test.php (Controller)
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
$this->output->enable_profiler(TRUE);
log_message('debug', "XXXXXXXXXXXX - Load DB from CTLer now");
$this->load->database();
log_message('debug', "XXXXXXXXXXXX - Load DB from CTLer done?");
log_message('debug', "XXYYYYYYAAA - Before Loginmodel-Load");
$this->load->model('loginmodel');
log_message('debug', "XXYYYYYYAAA - After Loginmodel-Load");
$data['query'] = $this->loginmodel->checkDB();
}
}
loginmodel.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Loginmodel extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
log_message('debug', "XXYYYYYYXXX - Constructor Loginmodel");
log_message('debug', "XXXXXXXXXXXX - Load Database now");
$this->load->database(); // line 12
log_message('debug', "XXXXXXXXXXXX - Load Database done?");
}
public function checkDB()
{
/*
* Look up user in database
*/
$query = $this->db->query('Select * from user');
return $query->result();
}
}
Error message on website:
Quote:Fatal error: Call to a member function database() on a non-object in E:\xampp180\htdocs\pdbase_v1\application\models\loginmodel.php on line 12
Log:
Quote:DEBUG - 2012-09-05 13:57:03 --> Config Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Hooks Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Utf8 Class Initialized
DEBUG - 2012-09-05 13:57:03 --> UTF-8 Support Enabled
DEBUG - 2012-09-05 13:57:03 --> URI Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Router Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Output Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Security Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Input Class Initialized
DEBUG - 2012-09-05 13:57:03 --> XSS Filtering completed
DEBUG - 2012-09-05 13:57:03 --> Global POST and COOKIE data sanitized
DEBUG - 2012-09-05 13:57:03 --> Language Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Loader Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Helper loaded: url_helper
DEBUG - 2012-09-05 13:57:03 --> Helper loaded: form_helper
DEBUG - 2012-09-05 13:57:03 --> Form Validation Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Controller Class Initialized
DEBUG - 2012-09-05 13:57:03 --> XXXXXXXXXXXX - Load DB from CTLer now
DEBUG - 2012-09-05 13:57:03 --> Database Driver Class Initialized
DEBUG - 2012-09-05 13:57:03 --> XXXXXXXXXXXX - Load DB from CTLer done?
DEBUG - 2012-09-05 13:57:03 --> XXYYYYYYAAA - Before Loginmodel-Load
DEBUG - 2012-09-05 13:57:03 --> Model Class Initialized
DEBUG - 2012-09-05 13:57:03 --> Model Class Initialized
DEBUG - 2012-09-05 13:57:03 --> XXYYYYYYXXX - Constructor Loginmodel
DEBUG - 2012-09-05 13:57:03 --> XXXXXXXXXXXX - Load Database now
Database is not autoloaded (but even if it is, there is no change)
Code:
$autoload['libraries'] = array( 'input', 'form_validation');
And it doesn't change anything, if I load the database in the CTLer or not.
So, where's the bug?
Thanks a lot!