我仍然在運行時手動連接到數據庫時遇到麻煩。我開了一個新問題,因爲沒有找到答案。CodeIgniter運行時數據庫連接
這裏是我與連接用戶來驗證輸入與形式的用戶名和密碼連接到數據庫的情況下,
。然後用這個新信息,如果用戶有效,我必須用這個新的用戶名和密碼連接到數據庫。長相包含以下內容:
配置/ database.php中
$active_record = TRUE;
$db['default']['hostname'] = 'host';
$db['default']['username'] = 'username';
$db['default']['password'] = 'pwd';
$db['default']['database'] = 'dbname';
$db['default']['dbdriver'] = 'oci8';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'WE8ISO8859P1';
$db['default']['dbcollat'] = '';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = FALSE;
$db['default']['stricton'] = FALSE;
在登錄控制器
然後:控制器/ login.php中
public function __construct(){
parent::__construct();
$this->output->enable_profiler(TRUE);
$this->CI =& get_instance();
$this->db_con = $this->CI->load->database('default', FALSE, TRUE);
$this->load->model('Login_model');
session_start();
}
public function index(){
if (isset($_POST['ingresar'])){
$d['data'] = $this->Login_model->Obtener_usuario($_POST['usuario']);
$_SESSION['logueo'] = $d['data']->row();
if (empty($_SESSION['logueo'])){
$d['error'] = 2;
}
else{
if (is_null($_SESSION['logueo']->USER_ORACLE)){
$d['error'] = 1;
}
if (!is_null($_SESSION['logueo']->N_SECUENCIA)){
cargar_var_sesion($_POST['usuario'], $_SESSION['logueo']->USER_ORACLE, $_SESSION['logueo']->N_SECUENCIA, $_SESSION['logueo']->C_USR_NOM_APE);
$db['limited']['hostname'] = 'samehost';
$db['limited']['username'] = $_POST['usuario'];
$db['limited']['password'] = $_POST['clave'];
$db['limited']['database'] = 'samedbname';
$db['limited']['dbdriver'] = 'oci8';
$db['limited']['dbprefix'] = '';
$db['limited']['pconnect'] = FALSE;
$db['limited']['db_debug'] = TRUE;
$db['limited']['cache_on'] = FALSE;
$db['limited']['cachedir'] = '';
$db['limited']['char_set'] = 'WE8ISO8859P1';
$db['limited']['dbcollat'] = '';
$db['limited']['swap_pre'] = '';
$db['limited']['autoinit'] = FALSE;
$db['limited']['stricton'] = FALSE;
$active_group = 'limited';
$this->db = $this->CI->load->database('limited', FALSE, TRUE);
redirect('inicio', 'location');
}
else{
$d['error'] = 2;
}
}
}
else{
$d['error'] = 0;
}
$this->load->view('/componentes/header');
$this->load->view('/componentes/menu_sin_login');
$this->load->view('/login/login', $d);
$this->load->view('/componentes/footer');
}
一切順利該控制器內確定,但當重定向是執行(加載不同的型號),例如,tareas_model.php我在第一行繼續收到相同的錯誤:
models/tareas_model.php
function __construct()
{
parent::__construct();
$query = $this->db->query('ALTER SESSION SET nls_sort = \'SPANISH\'');
}
的錯誤是:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Inicio::$db
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function query() on a non-object in /var/www/crm/application/models/tareas_model.php on line 8
我也試着設置$這個 - >分貝爲一個會話變量,但我不斷收到同樣的錯誤,我開車很瘋狂。我試過了我在網上找到的一切,但都沒有運氣。
任何幫助?
朋友你好!有沒有人對此有任何想法?我真的需要這個才能工作。提前致謝! – Veronica