Skip to content

Instantly share code, notes, and snippets.

@RelativeMedia
Created July 24, 2012 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RelativeMedia/08a4f45da1ff7e177425 to your computer and use it in GitHub Desktop.
Save RelativeMedia/08a4f45da1ff7e177425 to your computer and use it in GitHub Desktop.
//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();
}
}
@kabircse
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment