05-15-2017, 11:42 AM
Hello all,
I have developed a superadmin system that manages an admin interface for a lot of users, each with his own database. It is working well, but there's one situation that I'm not able to handle yet. When logging in, the superadmin supplies the ID of the database he will access. There are three alternatives as for the outcome:
However, in situation #2 the "conn_id" error is not reached. CodeIgniter steps in with the "Unable to connect to your database server using the provided settings." error and that's it.
Is there a way to handle this kind of connection error, so I can redirect to the previous page and inform the user? I don't want the CI error page to show.
Thank you very much for your help.
I have developed a superadmin system that manages an admin interface for a lot of users, each with his own database. It is working well, but there's one situation that I'm not able to handle yet. When logging in, the superadmin supplies the ID of the database he will access. There are three alternatives as for the outcome:
- The script retrieves the client's DB info and connects successfully;
- The script retrieves the client's DB info and does NOT connect successfully;
- The script cannot retrieve any data on that client and DB, and returns an error.
PHP Code:
$config['hostname'] = $row->server; // from the superadmin DB
$config['username'] = $row->user; // from the superadmin DB
$config['password'] = $password; // from the superadmin DB
$config['database'] = $row->db; // from the superadmin DB
$config['dbdriver'] = 'mysqli';
$config['dbprefix'] = '';
$config['pconnect'] = FALSE;
$config['db_debug'] = (ENVIRONMENT !== 'production');
$config['cache_on'] = FALSE;
$config['cachedir'] = '';
$config['char_set'] = 'utf8';
$config['dbcollat'] = 'utf8_general_ci';
$db_config = $config;
$this->db = $this->load->database($config, TRUE);
if($this->db->conn_id->connect_error) {
//error
return false;
}
However, in situation #2 the "conn_id" error is not reached. CodeIgniter steps in with the "Unable to connect to your database server using the provided settings." error and that's it.
Is there a way to handle this kind of connection error, so I can redirect to the previous page and inform the user? I don't want the CI error page to show.
Thank you very much for your help.