0

I have CodeIgnitor setup to pick the database based on the subdomain it is loaded in (as shown below).

I turned of persistent connections as I use temp tables and different databases. It seems to be working fine, but I was just wondering if there are any potential problems. (I also use database backed sessions)

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$active_group = "default";
$active_record = TRUE;
$phppos_client_name = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.'));
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "USER";
$db['default']['password'] = "PASSWORD";
$db['default']['database'] = 'db_'.$phppos_client_name;
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "phppos_";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";


/* End of file database.php */
/* Location: ./application/config/database.php */
Chris Muench
  • 17,444
  • 70
  • 209
  • 362

1 Answers1

0

It will work, but as user can enter any value for HTTP_HOST as it will be taken from HTTP request header. So, you should check HTTP_HOST 's value with available databases. As wrong value entered by user (misspelled sub-domain name) will give database error.

Or you can use SERVER_NAME, But please look at HTTP_HOST vs. SERVER_NAME discussion before switching.

Community
  • 1
  • 1
Pradeep
  • 1,254
  • 1
  • 22
  • 41