-
-
Save RelativeMedia/08a4f45da1ff7e177425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//My Controller | |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
class api extends REST_Controller{ | |
//-------------------------------------------------------------------- | |
public function __construct() { | |
parent::__construct(); | |
$this->lang->load('api'); | |
$api = $this->session->userdata('api'); | |
#$this->session->unset_userdata('api'); | |
$CI =& get_instance(); | |
$dbConfig['database'] = 'example_'.$api->api_dbname; | |
$dbConfig['dbprefix'] = 'exa_'; | |
$dbConfig['hostname'] = $this->db->hostname; | |
$dbConfig['username'] = $this->db->username; | |
$dbConfig['password'] = $this->db->password; | |
$dbConfig['dbdriver'] = $this->db->dbdriver; | |
$dbConfig['pconnect'] = $this->db->pconnect; | |
$dbConfig['db_debug'] = $this->db->db_debug; | |
$dbConfig['cache_on'] = $this->db->cache_on; | |
$dbConfig['cachedir'] = $this->db->cachedir; | |
$dbConfig['char_set'] = $this->db->char_set; | |
$dbConfig['dbcollat'] = $this->db->dbcollat; | |
$dbConfig['swap_pre'] = $this->db->swap_pre; | |
$dbConfig['autoinit'] = $this->db->autoinit; | |
$dbConfig['stricton'] = $this->db->stricton; | |
$CI->clientDb = $this->load->database($dbConfig, TRUE); | |
} | |
//My Model | |
<?php | |
class Map_users extends CI_Model { | |
function __construct() | |
{ | |
// Call the Model constructor | |
parent::__construct(); | |
} | |
/** | |
* Gets all rows from the table users per the Client's DB. The database is | |
* determined from their API key that it passed via header. | |
* @param array $params paramters for connection | |
* @param 'bannedFlag' 'bannedFlag' whether to only show members that aren't banned. | |
* @return object | |
*/ | |
function getAllUsers($params = array('activeFlag' => false, 'bannedFlag' => false)){ | |
$this->clientDb->select(' | |
id, | |
username, | |
firstname, | |
lastname, | |
email, | |
avatar | |
'); | |
$this->clientDb->from('users'); | |
if ($params['activeFlag'] == TRUE){ | |
$this->clientDb->where('activated', 1); | |
} | |
if ($params['bannedFlag'] == TRUE){ | |
$this->clientDb->where('banned', 0); | |
} | |
$this->clientDb->order_by('username', 'ASC'); | |
$query = $this->clientDb->get(); | |
return $query->result(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to use an basic database initially. When the user will be logged in. I will fetch his user information and his database that I have created manually. Using his login information I will replaced his databbase collecting his login information. Is is possible ?