CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 config.php login to different databases

Print topic Send  topic

Author Message
tomato

Posts: 11
Posted: 03/20/2009, 7:55 AM

Hi
Is there a solution to this:

http://forums.codecharge.com/posts.php?post_id=71096

Ie a user logs on and has their own db. But all users use the same php front end.
Each user has their own directory which holds a config.php file.In the config file holds their MYSQL db connection data. I tried to include in the common.php file but this did not work as their could be many different config files in different directories.


Thanks
Andrew
View profile  Send private message
mentecky

Posts: 321
Posted: 03/21/2009, 8:37 AM

I haven't posted here in a while, but I couldn't resist an attempt to answer this one.

I'm assuming each user's folder is a sub folder of the root here and named with the user's login. ie: ./tomato ./mentecky

Also assuming your config.php looks something like this:
<?php  
   $db_host = "host";  
   $db_database = "database";  
   $db_user = "user";  
   $db_password = "password";  
?>  

In common.php, just under the include section after "//End Include Files", you need something like:
// Default to a global config.php  
$db_include = RelativePath."/config.php";  
$db_temp = "";  
  
// If a user is logged in (or logging in) create a path to his config.php  
// This assumes your login form uses "login" for the user name  
if (CCGetUserLogin())  
{  
   $db_temp = RelativePath."/".CCGetUserLogin()."/config.php";  
}  
else if (CCGetParam("login", "") != "")  
{  
   $db_temp = RelativePath."/".CCGetParam("login", "") ."/config.php";  
}  
  
// If a user path was set and the file exists we use that instead of the default  
if ($db_temp != "" && file_exists( $db_temp ) )  
{  
   $db_include = $db_temp;  
}    
  
// Include our config.php based on user name  
include($db_include);  

That's all the code. Now in your connection settings on the server tab enter the following:
Database or ODBC Connection: $db_database
Host: $db_host
Login: $db_user
Password: $db_password

I haven't tested this obviously, but it should work or at least be really close.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
mentecky

Posts: 321
Posted: 03/21/2009, 9:11 AM

I just checked the generated code and after you do the above process you will have to generate common.php. Then just below where you added the code remove the "\" from the connection settings. CodeCharge escapes the $ which will mess up your logins. This shouldn't be a problem for you though because CodeCharge will not regenerate a block you have edited.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
tomato

Posts: 11
Posted: 03/22/2009, 3:18 AM

Hi
Thanks. I will try this tomorrow.
Thanks for your time
Regards
Andrew
View profile  Send private message
tomato

Posts: 11
Posted: 03/22/2009, 3:43 PM

Hi
Thanks for your previous post. The only issue I am working through (which I omitted to mention) before is that users are split up via organisation with the db belonging to the organisations rather unique user.
At present I am trying two options.
1/ Users enter an Org ID, username and password when they login. or
2/ Each Org has a login page in their folder so I can use the folder name (which will be part of the url) as the path to the config.php file.
Thanks
Andrew
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.