我正在开发codeigniter site.I有一个应用程序这个应用程序被各种用户使用,每个用户都拥有自己的DB(也是自己的客户端)。我需要如何处理这个云系统的方式。 因为我有应用程序文件夹的单个副本,并且每个用户只有DB的差异。 我已经尝试在codeigniter中创建子域目录并编写索引文件和htaccess文件,以便我可以访问我的原始应用程序。但我需要url中的子域路径以及如何根据该子网站url路径连接到数据库。
htaccess文件。
RewriteEngine On
RewriteRule /test/(.*) /$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
我应该按照哪种方式完成这项工作。请帮助 提前谢谢。
答案 0 :(得分:2)
以下是我们的工作:
在config / database.php中,我们定义了一组不同的数据库设置,这些设置是基于域选择的。您可以轻松调整/扩展。
if($_SERVER['SERVER_NAME'] == 'www.stagingserver.com'){
$active_group = "staging";
$db['staging']['hostname'] = "95.xxx.xxx.xxx";
} else {
$active_group = "default";
}
$db['default']['hostname'] = "localhost:8889";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "database";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['staging']['username'] = "movers_user";
$db['staging']['password'] = "staging_user";
$db['staging']['database'] = "staging_database";
$db['staging']['dbdriver'] = "mysql";
$db['staging']['dbprefix'] = "";
$db['staging']['pconnect'] = TRUE;
$db['staging']['db_debug'] = TRUE;
$db['staging']['cache_on'] = FALSE;
$db['staging']['cachedir'] = "";
$db['staging']['char_set'] = "utf8";
$db['staging']['dbcollat'] = "utf8_general_ci";
答案 1 :(得分:2)
我试过这样的事...... 在我的database.php文件中
$active_group = 'default';
$active_record = TRUE;
$uri = $_SERVER['REQUEST_URI'];
$pieces = explode('/', $uri);
if($pieces[1]==""){
$_SESSION['user_db_username']='**';
$_SESSION['user_db_pass']='**';
$_SESSION['user_db_name']='**';
}
else
{
$link = mysql_connect('**', '**', '**');
if($link){
$db_selected = mysql_select_db('**', $link);
if ($db_selected)
{
$query_arr= "SELECT * FROM ** where domain='".$pieces[1]."' ";
$queryResult_arr=mysql_query($query_arr,$link);
while($row=mysql_fetch_assoc($queryResult_arr))
{
$_SESSION['user_db_user']=$row['**'];
$_SESSION['user_db_pass']=$row['**'];
$_SESSION['user_db_name']=$row['**'];
}
}
}
}
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = $_SESSION['user_db_username'];
$db['default']['password'] = $_SESSION['user_db_pass'];
$db['default']['database'] = $_SESSION['user_db_name'];