computermax2328 Posted December 3, 2012 Share Posted December 3, 2012 Hello All, I haven't been here in a while. It has been a busy semester. Haven't gotten a lot of time to practice coding in a while, but this question did cross my mind this morning for a project I am working on. Is there a way to connect to a database that is not the host. For example, say I was to create a blog with PHP and I gave that system to multiple users, but I wanted to collect all of the posts from all of the blogs in my database. So each blog has it's own database and different hosts, but I have my own that collects all of the posts and content. Any ideas?? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/ Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 So you have a copy of everything? Or the posts actually live on your database while the rest is in the per-blog database? What blogging software are you using? Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/#findComment-1397246 Share on other sites More sharing options...
computermax2328 Posted December 3, 2012 Author Share Posted December 3, 2012 I was just using a blog as an example. Well would it be easier to query your own database and build off of that or query their database and build off of theirs. For example, if there are 3 blogs, blog 1, blog 2 and my blog and blog 1 and 2 are their own unique content and I wanted my blog to be content from both of their blogs. But remember that the blogs they are using are a part of a system that I built for them. I would prefer to query my own database and connect to their database, but what if they are using another host?? Is this making sense?? Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/#findComment-1397254 Share on other sites More sharing options...
berridgeab Posted December 3, 2012 Share Posted December 3, 2012 So two MySQL databases on different servers? Yes it is possible, as long as the remote database allows non-local access. Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/#findComment-1397256 Share on other sites More sharing options...
computermax2328 Posted December 3, 2012 Author Share Posted December 3, 2012 Ideally, the two MYSQL databases would have similar structure, but the contents database would be different. Anything on how to set up a remote MYSQL database?? Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/#findComment-1397290 Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 Just like you'd set up any other connection, just replace "localhost" with the IP-address of the host in question. I do recommend using MySQLI or PDO for this, so that you have a specific object for each DB connection. In addition to all the other reasons you should be using them. Quote Link to comment https://forums.phpfreaks.com/topic/271544-connect-to-database-that-isnt-host/#findComment-1397428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.