Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

using multiple databases

Asked Modified Viewed 1,870 times
C
Cupid
C
Cupid 10
  • Member, joined since
  • Contributed 151 posts on the community forums.
  • Started 49 threads in the forums
  • Started this discussions
asked
Member

So I'm currently running v7 since I'm having problems upgrading to v8.

Anyway. I'm sure the answer will be similar.

How would I have php-fusion connect to two databases at the same time?

I want to have a completely different site but using the users from a different database. Using multisite_includes if possible.

Thank you for your advice!
0 replies

11 posts

F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

Essentially start with a new connection within your Fusion site and trigger it then reconnect to current with default config.
If you do it on 8 you will need a db_driver var aswell. see config.php for full syntaxes.

But this is the basics of it all.

<?php
$server = "localhost"; // New Server
$username = ""; // Username
$password = ""; // Password
$database_name ="NEW_DATABASE"; // New Database

// Actions, includes etc.


// Reconnect to Fusion database, do any new includes required first.
dbconnect($db_host, $db_user, $db_pass, $db_name);
Edited by N/A on 13-04-2019 01:37,
0 replies
C
Cupid
C
Cupid 10
  • Member, joined since
  • Contributed 151 posts on the community forums.
  • Started 49 threads in the forums
  • Started this discussions
answered
Member

I see. So would that code have to go into the maincore.php or be a separate file?

Forgive me I don't know much about php but I am watching some videos and trying to learn.

How does it know to grab information from 2 databases?
0 replies
F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

You could make 2 config files and include a new one for the app / file you want to switch database in the opening, like after maincore.php add include config_2.php then run a connect sequence on it , dbconnect($db_host, $db_user, $db_pass, $db_name);

at the end of the script include config.php and reconnect.
0 replies
C
Cupid
C
Cupid 10
  • Member, joined since
  • Contributed 151 posts on the community forums.
  • Started 49 threads in the forums
  • Started this discussions
answered
Member

cupid.vivalavoltz.com/images/linksonsites/iam5.jpg


Sorry like I said. I'm not very good at PHP yet. If you don't mind. I think I get the basics of what you're trying to say.
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

The main thing is You van use only one database connection at a time.
0 replies
S
songiuno
S
  • Member, joined since
  • Contributed 55 posts on the community forums.
  • Started 13 threads in the forums
answered
Member

It sounds like you want to have two completely separate sites but share the same user database? That's almost exactly what multi-site is, and I run two independent PHPFusion sites except they share the same user database. To do this I followed the steps that are in the PHPFusion v7 manual. You may want to see if this suits your requirements?
1 reply
F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

It is not possible without doing heavy modifications to the Core, unless you have very few areas where it should be applicable and can switch database as per description in them few areas.
0 replies
D
douwe_yntema
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question
answered
Senior Member

Maybe you can setup master slave replication between the two databases, so the data from the remote database is also available in the local database as a copy
1 reply
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

If I am reading this right, you want to make a second site but use back the old user pool you have in the first site? I want to confirm on this before I provide my answer.
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

@Cupid

Okay, then you can use the dbconnect() and then tie it to your 2nd's site DB_USERS.

In your 2nd site, see this line https://github.com/PHPFusion/PHPFusio...ss.php#L51

Before Line 51.

$db_host = 'localhost';
$db_user = 'your-site1-db-user';
$db_pass = 'your-site1-db-pass';
$db_name = 'your-site1-dbname';
$db_port = 3306;
dbconnect($db_host, $db_user, $db_pass, $db_name, !empty($db_port) ? $db_port : 3306);
unset($db_host, $db_user, $db_pass, $db_port);


Then, you need to reconnect to back to the previous connection here:
https://github.com/PHPFusion/PHPFusio...e.php#L207

include BASEDIR.'config.php';
$link = @dbconnect($db_host, $db_user, $db_pass, $db_name, !empty($db_port) ? $db_port : 3306);
unset($db_host, $db_user, $db_pass, $db_port);


Now compare both site's config.php file, make sure the site2 one is same as site1

define("COOKIE_PREFIX", "loremipsum_");


This will give your user same persistent login and when they visit the second site, they are continued to be login state.

Multisite is just is not as it seems. Don't be misguided :) That file should read 'constants.php'

To have "multisite" you need - "multi" connections, but as everyone had mentioned here, you can only have 1 active connection. So you need to know where to close a connection and open a new connection line by the process workflow.

[bcolor=#ffffcc]Caveat: I have not tested any of this. There are 2 system version 8 and version 9 to look into. I'm just typing this from the back of my head. These are just pointers to get you going. I don't have much room for another side lined test case. I have already 40+ open tabs on my IDE now. I can't lose my focus at this moment :)[/bcolor]
Edited by Chan on 19-04-2019 04:40,
0 replies
C
Cupid
C
Cupid 10
  • Member, joined since
  • Contributed 151 posts on the community forums.
  • Started 49 threads in the forums
  • Started this discussions
answered
Member

Thank you for your response! I think I'm going to focus more on getting my sites up to date first and then worry about this.

It's not necessary right now since I could just use multi site.
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 11 posts
  • Votes 0 votes
  • Topic users 5 members

5 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
S
S
  • Member, joined since
  • Contributed 55 posts on the community forums.
  • Started 13 threads in the forums
C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
C
C
Cupid 10
  • Member, joined since
  • Contributed 151 posts on the community forums.
  • Started 49 threads in the forums
  • Started this discussions
D
D
  • Senior Member, joined since
  • Contributed 667 posts on the community forums.
  • Started 57 threads in the forums
  • Answered 1 question

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet