From what I understand, you will have to use many databases, and you do not want to duplicate the application just for that.
In case you were going to do it:
- www.meusite.com/app1
- www.meusite.com/app2
- www.meusite.com/app3
- www.meusite.com/app4
There is an interesting solution on the site:
http://www.oficinadanet.com.br/post/10349-codeigniter-conectando-ao-banco-de-dados-automaticamente-de-acordo-com-o-ambiente
I don’t know if it’s appropriate because I’m not an expert on Codeigniter.
I’ve tested it and it works well.
What I do is to know which folder the user has entered to direct to the correct database using the SWITCH information.
I hope it helps!
UPDATING:
I don’t know if you’re okay with security. If anyone can help, I’d appreciate it!
Look for the file "index php." which is at the root of Codeigniter and change the following lines (make a copy of the original file).
Change "app1, app2, app3, app4" to the name of the folder that appears in the URL.
Example: www.meusite.com/minhapasta
//Changed constant to my folder -> request_uri
$get_uri = $_SERVER['REQUEST_URI'];
$get_uri = filter_var($get_uri, FILTER_SANITIZE_STRING);
$get_uri = explode('/',$get_uri);
$get_uri = $get_uri[1];
$redirect = $get_uri;
define('ENVIRONMENT', $redirect);
if (defined('ENVIRONMENT')) {
switch (ENVIRONMENT) {
case 'development':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
case 'app1':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
case 'app2':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
case 'app3':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
case 'app4':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
case 'production':
$db['default']['hostname'] = 'host do banco de dados';
$db['default']['username'] = 'usuário do banco de dados';
$db['default']['password'] = 'senha do banco de dados';
$db['default']['database'] = 'nome do banco de dados';
break;
default:
exit('Minha mensagem de erro personalizada aqui!!!');
}
}
Dear, your question is quite broad and probably someone will vote to close it by the way it is written. What I can recommend is reading about code versioning, deployment strategies and environment control for your application.
– gmsantos
My dear, I realize what you said about closing. On your recommendation, I know part of what you said. What I wanted was something directly related to Codeigniter. With pure PHP it’s much simpler and I’ve done it many times. The problem is that Codeigniter for me is a bit confusing and I would like someone expert in it to give me some hint about it in Codeigniter. But thank you for the recommendation. All the tips I found on the internet are very time consuming to apply. I believe someone has some better idea and that someone might be here at Stackoverflow. Thanks friend. ;)
– user737