0

I already make this in database.php:

   /* user */
$active_group = "user";
$active_record = TRUE;
$db['user']['hostname'] = "jkt";
$db['user']['username'] = "calculation";
$db['user']['password'] = "C4lculation";
$db['user']['database'] = "MedsLi";
$db['user']['dbdriver'] = "sqlsrv";
$db['user']['dbprefix'] = "";
$db['user']['pconnect'] = TRUE;
$db['user']['db_debug'] = TRUE;
$db['user']['cache_on'] = FALSE;
$db['user']['cachedir'] = "";
$db['user']['char_set'] = "utf8";
$db['user']['dbcollat'] = "utf8_general_ci";

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "maindatabase";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
<br/>'

but the colomn and table in $db['user']['hostname'] = "jkt"; still can not connect. default is for database admin (mysql); user is for database that user can access (sql server).

error:

    A PHP Error was encountered

    Severity: Notice

    Message: Undefined property: stdClass::$Comp_Name

    Filename: views/HCM_user_view.php

    Line Number: 36


Please help

this is the model:

$this->db->select('*');
$this->db->limit(100);
$this->db->from('cm');
$query = $this->db->get();
$myRow = $query->row();         
return $query;

view error:

foreach($allHCM->result() as $row)
    php echo $row->trans_ref
    php echo $row->Cert_No
    php echo $row->Comp_Name
    php echo $row->status_code
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
anakpanti
  • 15
  • 4
  • `var_dump($allHCM->result());` and what you get? – Bora Aug 21 '13 at 07:45
  • array(1) { [0]=> object(stdClass)#20 (5) { ["id"]=> string(1) "1" ["titleReport"]=> string(8) "Data PMR" ["division"]=> string(3) "HCM" ["descriptionHCM"]=> string(18) "Sample Description" ["file"]=> string(10) "Sample.xls" } } – anakpanti Aug 21 '13 at 07:49
  • it's still not connect to sql server.. the value is from mysql -> my localhost data – anakpanti Aug 21 '13 at 07:51
  • This results is not true? Your object not null. You get results. Could you paste `Line Number: 36` ? – Bora Aug 21 '13 at 07:52
  • You complain that your database is not connected, yet post an error related to a view. Post code that verifies your connection has failed. For the error in your view post view code – allen213 Aug 21 '13 at 07:56
  • that's the view, $row did not recognized by view.. that's my colomn name in my table sql server(trans_ref, Cert_No, etc.). – anakpanti Aug 21 '13 at 08:03

2 Answers2

0

If I can understand you well you should use

$db['default']['dbdriver'] = 'sqlsrv';

for connecting to sqlserver, look at this question here

CodeIgniter MSSQL connection

Community
  • 1
  • 1
Shashi
  • 474
  • 6
  • 21
0

you must set pconnect true in one database, not two of them...

and... try this code for multiple connection...

$DB1 = $this->load->database('default', TRUE);
$DB2 = $this->load->database('user', TRUE); 

use ....

$DB1->get('tablename');

or ...

$DB2->get('tblname');

not ....

$this->db->get('tablename'); // if you use this, this will load the default database....
Eko Junaidi Salam
  • 1,663
  • 1
  • 18
  • 26