This topic is locked

How to make single project connect to different databases passing database name via URL?

6/11/2014 5:55:25 PM
PHPRunner Tips and Tricks
admin

Q: I have created a script that works, but it is assigned to just one database. I have a number of identical databases on same server, and would like to assign each one when they login. Is there a way to do that? table names are all the same.
A:

Here is an example of how this can be done

  • create a new server database connection in PHPRunner ('Output directory' screen)

    Assuming that you use MySQL, leave all connection parameters intact except database name. Modify the last line according to my example.



if($_GET["dbname"])

$_SESSION["dbname"]=$_GET["dbname"];
$host="localhost";

$user="root";

$pwd="";

$port="";

$sys_dbname=$_SESSION["dbname"];


  • now you can point users to the URL like this one:

http://mywebsite.com/login.php?dbname=database_name_here
A
asawyer13DevClub member 1/8/2016

Seems like it would be better to do something like have a table in a system wide database to login, and then in the user table specify the database to use. Not sure I could code it in PHPR but I would think that would be a better solution than providing it on the URL, though the URL option would work.
If would be very interesting to me to see how that could be done in PHPR since that essentially makes the app a multi-tenancy app which is very popular.

A
afa1999 1/9/2019



Q: I have created a script that works, but it is assigned to just one database. I have a number of identical databases on same server, and would like to assign each one when they login. Is there a way to do that? table names are all the same.
A:

Here is an example of how this can be done

  • create a new server database connection in PHPRunner ('Output directory' screen)

    Assuming that you use MySQL, leave all connection parameters intact except database name. Modify the last line according to my example.



if($_GET["dbname"])

$_SESSION["dbname"]=$_GET["dbname"];
$host="localhost";

$user="root";

$pwd="";

$port="";

$sys_dbname=$_SESSION["dbname"];


  • now you can point users to the URL like this one:

http://mywebsite.com/login.php?dbname=database_name_here



Hi,

I tried how you described but I couldnt find how to forward the user related folder.

I have Users db. And I have Personnel db.

I created 2 projects as users and personnel.

I would like to direct the users who has selected dbname=personnel to personnel folder under htdocs

Could you please advise?

What I do wrong!