Welcome Guest, Not a member yet? Register   Sign In
Can some one help me with this database connectiong issue
#3

[eluser]tiffany1988[/eluser]
[quote author="PravinS" date="1377930148"]Check this

http://ellislab.com/codeigniter/user-gui...ation.html[/quote]

Hey Pravin ,

Thank you . I did check that page but it doesn't seem to help either.

Here's what we are trying to do .

we have multiple localhost servers with different IP's we are tryig to fetch the tables of that servers by selecting the server name .

First you will select the server name :
We fetch the server credentials using that name
then we have to pass that to the database query function

this is the code we are working with see if you can help me .

thank you so much honey.

Code:
<?php

class M_main extends CI_Model
{
      //  var $db_group_name = "default";
        function __construct(){

        parent::__construct();
        $this->load->database();
      //  $this->{$this->db_group_name} = $this->load->database($this->db_group_name, TRUE);
  
        }
        
             function get_serv_list()
        {
            //echo "test get_server_list";
               $this->db->select('srv_name');
               $query = $this->db->get("srv_mng");
               $result= $query->result_array();
               return $result;
            
        }
        
            function get_db_list($ser_name)
            {
               // echo $ser_name;
                $srv_cred=$this->get_ser_cred($ser_name);
               // print_r($srv_cred);
                $db_list=$this->get_db_lst($srv_cred);
            }
            
            function get_ser_cred($ser_name)
            {
               $this->db->where('srv_name',$ser_name);
               $query = $this->db->get('srv_mng');
               return ($query->result_array());
            }

// here passing the serv credentials
            function get_db_lst($srv_cred)
            {
                //print_r($srv_cred);
                    foreach ($srv_cred as $key => $value) {
                  //  print_r($value);
                    $ip_add = $value['ip_add'];
                    $uname=$value['sql_uname'];
                    $pswd =$value['pswd'];
                    }
                    $this->connectDb($ip_add,$uname,$pswd);
            }
        

// trying to connect to that database    
            function connectDb($ip_add,$uname,$pswd)
            {
                
//                $db['otherdb']['hostname'] = $ip_add;
//                $db['otherdb']['username'] = $uname;
//                $db['otherdb']['password'] = $pswd;
//                $db['otherdb']['database'] = "";
//                $db['otherdb']['dbdriver'] = "mysql";
//                $db['otherdb']['dbprefix'] = "";
//                $db['otherdb']['pconnect'] = TRUE;
//                $db['otherdb']['db_debug'] = FALSE;
//                $db['otherdb']['cache_on'] = FALSE;
//                $db['otherdb']['cachedir'] = "";
//                $db['otherdb']['char_set'] = "utf8";
//                $db['otherdb']['dbcollat'] = "utf8_general_ci";
//                $db['otherdb']['swap_pre'] = "";
//                $db['otherdb']['autoinit'] = TRUE;
//                $db['otherdb']['stricton'] = FALSE;
                
                $db['alternate']['hostname'] = $ip_add;
                $db['alternate']['username'] = $uname;
                $db['alternate']['password'] = $pswd;
                $db['alternate']['database'] = "CARDZME";
                $db['alternate']['dbdriver'] = "mysql";
                $db['alternate']['dbprefix'] = "";
                $db['alternate']['pconnect'] = TRUE;
                $db['alternate']['db_debug'] = TRUE;
                $db['alternate']['cache_on'] = FALSE;
                $db['alternate']['cachedir'] = "";
                $db['alternate']['char_set'] = "utf8";
                $db['alternate']['dbcollat'] = "utf8_general_ci";
                
                
              
               // echo"<br>.between.<br>";
               $otherdb =  $this->load->database($db['alternate'], TRUE);
                print_r($otherdb);
                $dbsel = $this->db->select('alternate');
                
               // print_r($dbsel);
             //  $this->legacy_db->dbutil();
            //   $query = $this->dbutil->list_databases();
//               print_r($query);
//               var_dump($query);
              // $dbutil  =  $otherdb->dbutil();
              //
              // print_r($dbutil);
              // $query = $otherdb->select('first_name, last_name')->get('person');
              //  $query = $this->dbutil->list_databases();
              // print_r($query);
                exit();
            }
}          

    ?&gt;


Messages In This Thread
Can some one help me with this database connectiong issue - by El Forum - 08-30-2013, 11:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB