使用會話,我需要你的笨項目的幫助。我想使用會話動態更改數據庫文件在config文件夾中的數據庫。 我做$ DB [ '默認'] [ '數據庫'] = $ _SESSION [ 'DB_NAME'],在配置文件中,但不工作。 登錄頁面應檢查進行登錄的其他數據庫訪問權限。笨的數據庫類
是否有可能改變選擇數據庫之前的連接?
登錄頁面
public function login(){
if(!$this->session->userdata('id_funcionario') || !$this->session->userdata('logado')){
$this->db->database= "test";
$this->session->destroy();
$subdomain = $_SERVER['HTTP_HOST'];
$this->db->select("database");
$this->db->where("subdomain", $subdomain);
$access = $this->db->get("table")->row();
$this->session->set_userdata("database", $access->database);
$this->load->view('/geral/login');
}else{
$url = base_url('home');
header("Location: $url ");
}
}
登錄頁面的作品!
的數據發送的AJAX來:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('html');
$this->load->library('session');
}
public function toLog()
{
$email = $this->input->post('email');
$pass= md5($this->input->post('pass'));
$this->db->database = $this->session->userdata('database');
$this->db->select('*');
$this->db->from('users');
$this->db->where('usu_email',$email);
$this->db->where('usu_pass',$pass);
$usuario = $this->db->get()->result();
但我不知道如何在查詢的時候更改數據庫的名稱。我已經嘗試過,並且保持不變。
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Database Driver Class
*
* This is the platform-independent base DB implementation class.
* This class will not be called directly. Rather, the adapter
* class for the specific database will extend and instantiate it.
*
*/
class CI_DB_driver {
var $username;
var $password;
var $hostname;
var $database;
.......
/**
* Constructor. Accepts one parameter containing the database
* connection settings.
*
* @param array
*/
function __construct($params)
{
if (is_array($params))
{
foreach ($params as $key => $val)
{
$this->$key = $val;
}
}
$CI = & get_instance();
$this->database = $CI->session->userdata('database');
log_message('debug', 'Database Driver Class Initialized');
}....
你能幫幫我嗎?