3

我正在使用 codeigniter 站点。我有一个应用程序,该应用程序由各种用户使用,每个用户都有自己的数据库(也有自己的客户端)。我需要如何处理这个云系统的方法。因为我有应用程序文件夹的单个副本,并且每个用户的数据库只有差异。我尝试通过在 codeigniter 中创建子域目录并编写索引文件和 htaccess 文件,以便我可以访问我的原始应用程序。但我需要 url 中的子域路径以及如何根据该子域 url 路径连接到数据库的方式。

htaccess 文件。

RewriteEngine On 
RewriteRule /test/(.*) /$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

我应该按照哪种方式完成这项工作。请提前帮助谢谢。

4

2 回答 2

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'];
于 2013-05-16T09:09:18.050 回答
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";
于 2013-05-13T06:32:27.943 回答