Membuat koneksi dua database di codeigniter
contoh sintax pemanggilannya
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Siswa_model extends CI_Model {
// db2 digunakan untuk mengakses database ke-2
private $db2;
public function __construct()
{
parent::__construct();
$this->db2 = $this->load->database('data_siswa2', TRUE);
}
public function get_db1()
{
return $this->db->get('siswa');
}
public function get_db2()
{
return $this->db2->get('siswa');
}
}
atau juga menggunakan :
public function get_all_buku()
{
$this->db2 = $this->load->database('database2', TRUE);
$this->db2->limit(100);
$query = $this->db2->order_by('ModifiedDate','DESC')->get('ItemZonePrice');
return $query->result();
}
koneksinya
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'SANCESE-PC';
$db['default']['username'] = 'sa';
$db['default']['password'] = '123456';
$db['default']['database'] = 'PurchasingIndonesia';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;//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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['database2']['hostname'] = 'SANCESE-PC';
$db['database2']['username'] = 'sa';
$db['database2']['password'] = '123456';
$db['database2']['database'] = 'PurchasingIndonesia';
$db['database2']['dbdriver'] = 'sqlsrv';
$db['database2']['dbprefix'] = '';
$db['database2']['pconnect'] = FALSE;//TRUE
$db['database2']['db_debug'] = TRUE;
$db['database2']['cache_on'] = FALSE;
$db['database2']['cachedir'] = '';
$db['database2']['char_set'] = 'utf8';
$db['database2']['dbcollat'] = 'utf8_general_ci';
$db['database2']['swap_pre'] = '';
$db['database2']['autoinit'] = TRUE;
$db['database2']['stricton'] = FALSE;
Referensi : http://otakscript.blogspot.com/2015/06/koneksi-multi-database-di-codeigniter-3.html
Membuat koneksi dua database di codeigniter
Reviewed by Leo
on
22:00
Rating:
No comments