Welcome Guest, Not a member yet? Register   Sign In
multiple database connectivity getting errors
#1

[eluser]ranjitbd[/eluser]
Code:
//multiple database connection
// this is the code inside config/database.php
$active_group = "default";

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "tmartdb";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['active_r'] = TRUE;
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";

$db1['default']['hostname'] = "localhost";
$db1['default']['username'] = "root";
$db1['default']['password'] = "";
$db1['default']['database'] = "holidaysdb";
$db1['default']['dbdriver'] = "mysql";
$db1['default']['dbprefix'] = "";
$db1['default']['active_r'] = TRUE;
$db1['default']['pconnect'] = TRUE;
$db1['default']['db_debug'] = TRUE;
$db1['default']['cache_on'] = FALSE;
$db1['default']['cachedir'] = "";

//and this is the code inside the model

<?php
<?php
class HolidayModel extends Model
{
    function HolidayModel()
    {
      // $this->load->database('holidaysdb');
    }
    
    function getHolidayPackage()
    {
        /*
        $DB1 = $this->load->database('holidaysdb',TRUE);
        $query = $DB1->get('destination');
        */
        $query = $this->db1->get('destination');
        return $query->result();
    }
    
}    
?>

//it showing the error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: HolidayModel::$db1

Filename: holiday/holidayModel.php

Line Number: 15

Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\travelmartbd\application\models\holiday\holidayModel.php on line 15


//please help
#2

[eluser]elvix[/eluser]
you have two problems:

first change $db1 to $db and rename your 2nd db to something that's not 'default' -- $db['somethingelse'].

Second, set pconnect on your second db to false. You cannot have two db connections with persistent connections. You shouldn't see a noticeable performance hit.




Theme © iAndrew 2016 - Forum software by © MyBB