
-----------------------------------
peterggmss
Mon Oct 30, 2006 9:29 pm

Using multiple databases with PHP
-----------------------------------
Hello,
On my own, and for a self-inspired and self-directed work project not for school, I'm building a system with user management where companies can launch their PHP/MySQL applications and have us manage the users, fees, etc.  This system has many uses, such as another system I'm developing as a self-inspired and self-directed work project.

Bit of background on my project:
My grandmother is a real estate brokerage and we find that the recordkeeping is a lot of work as data doesn't magically move between Word, Excel, TorontoMLS, and her Real Estate Trust Account records.  I'm developing a system similar to quick!office commander The Problem
There will be different solutions launched on the [URL=http://www.redforums.ca]Red Forums Solution Launcher.  We will need a system with one database for each user (rfusers) and different databases for each solution (realestate, financing, relaw, etc.).  I need to store the users in rfusers and the information in realestate, financing or relaw - depending on which service they purchase.  I need to know how to do this, right now I have no code as I'm just starting to learn PHP and SQL, but I can see how powerful they are when combined.

-----------------------------------
rdrake
Mon Oct 30, 2006 10:04 pm


-----------------------------------
As I recall.

-----------------------------------
Tony
Mon Oct 30, 2006 10:30 pm


-----------------------------------
yey for [url=http://phpgacl.sourceforge.net/]phpGACL... it's like... almost no work on your part now

-----------------------------------
octopi
Mon Oct 30, 2006 10:40 pm


-----------------------------------
Tony is almost correct, you can also have different connections too.


$local = mysql_connect("localhost", "root", ""); 
$remote = mysql_connect("someremotehost", "username", "");
mysql_select_db("database1", $local); 
mysql_select_db("database2", $remote);

$result=mysql_query("SHOW TABLES FROM `database1`;",$local);
$result_remote=mysql_query("SHOW TABLES FROM `database2`;",$remote);


//etc....
 
You specify the 'link' which is the connection to the mysql server.

Also, I don't want to discourage you, but Its very hard to make such a complex program. Make sure you do tons of planning work before you start coding, make sure you know how things are going to fit together, and work, this way you will avoid problems down the line...that require a sort of patchy solution (which is no good).

Good luck!, feel free to pm if you need any help.

-----------------------------------
rdrake
Mon Oct 30, 2006 11:12 pm


-----------------------------------
Most interesting, Octopi.  Didn't know you could to that.

My suggestion would be to use as little databases per client as possible though if you can.  If need be, you can resort to table prefixes.  Many hosts (still) seem to charge for extra databases, plus it leads to a more complex install.

-----------------------------------
PeterK
Wed Aug 01, 2012 5:21 pm

Re: Using multiple databases with PHP
-----------------------------------
As I recall.

This is WRONG, mysql_select_db returns only true or false.

handler is for mysql_connect, it works like this:

    $conn1 = mysql_connect("localhost", "root1", "");
    $conn2 = mysql_connect("localhost", "root2", "");

    mysql_select_db("database1", $conn1);
    $result1 = mysql_query("SELECT * FROM table1", $conn1);
    mysql_select_db("database2", $conn1);
    $result2 = mysql_query("SELECT * FROM table2", $conn1);
    mysql_select_db("database1", $conn2);
    $result3 = mysql_query("SELECT * FROM table1", $conn2);
    mysql_select_db("database2", $conn2);
    $result4 = mysql_query("SELECT * FROM table2", $conn2);

-----------------------------------
Dreadnought
Wed Aug 01, 2012 5:25 pm

Re: Using multiple databases with PHP
-----------------------------------
Out of curiosity, is there a function to send a post 6 years into the past?
