I am looking to use/connect to a different database for one of my controllers and one model. I posted this hear since on the forums of CI I am getting no response.
I added this in database.php:
$db['tdb']['hostname'] = "localhost";//localhost
$db['tdb']['username'] = "username";//root
$db['tdb']['password'] = "password";//empty
$db['tdb']['database'] = "databasename";
$db['tdb']['dbdriver'] = "mysql";
$db['tdb']['dbprefix'] = "";
$db['tdb']['pconnect'] = FALSE;
$db['tdb']['db_debug'] = FALSE;
$db['tdb']['cache_on'] = FALSE;
$db['tdb']['cachedir'] = "";
$db['tdb']['char_set'] = "utf8";
$db['tdb']['dbcollat'] = "utf8_general_ci";
This as my model:
<?php
class Tadmin_model extends Model{
function Tadmin_model(){
parent::Model();
$tdb = $this->load->database('tdb', TRUE);
}
function FInsert($usernames){
$query = $tdb->query("SELECT * FROM following");
return $query->row();
}
}
?>
And this is the start of my controller:
<?php
class Tadmin extends Controller{
function Tradmin(){
parent::Controller();
$this->load->model('tadmin_model');
And I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: tdb
Filename: models/tadmin_model.php
Line Number: ...
Fatal error: Call to a member function query() on a non-object in /blablabla/tadmin_model.php on line ...
What am I doing wrong here?
Thank you very much,
Ace
p.s. changed some some lines for security purposes