?
Solved

Two domains using the same MySql database?

Posted on 2011-02-19
8
Medium Priority
?
419 Views
Last Modified: 2012-05-11
We have one website up and running in shared hosting environment and recently we obtained second domain name (for the site with completely different content). Both sites will be hosted by the same hosting company. Now, the second domain is what they call "addon domain" - as far as I understand, it will be set up inside public_html folder of the first site, but will have completely separate files, databases etc.

Is it possible for these two sites to somehow use the same database?  The new site needs to use some data from MySql database associated with the existing site.

Thanks.  
0
Comment
Question by:Erie_Laker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Accepted Solution

by:
andreizz earned 288 total points
ID: 34933964
It depends on your host, normally it would be possible.
0
 
LVL 2

Assisted Solution

by:PhSyChoTiK
PhSyChoTiK earned 288 total points
ID: 34933985
Yes it is possible, unless there is a restriction imposed on the MySQL account that prohibits access from other domains aside from the one it was set up for (and that isn't normally the case). And in that case, you can always create the access scripts on the first domain and poll them from the second.
0
 
LVL 5

Assisted Solution

by:onemadeye
onemadeye earned 284 total points
ID: 34933996
I think I once tried it works successfully on a Linux Hosting with CPanel.
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 284 total points
ID: 34934049
In my experience with addon domains, where the root directory contains more than one web site, I have been able to share data bases.  You might run this script on both and see if it works.
<?php // RAY_mysql_example.php
error_reporting(E_ALL);


// IMPORTANT PAGES FROM THE MANUALS
// MAN PAGE: http://php.net/manual/en/ref.mysql.php
// MAN PAGE: http://php.net/manual/en/mysql.installation.php
// MAN PAGE: http://php.net/manual/en/function.mysql-error.php


// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB CONNECTION: ";
    echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB SELECTION: ";
    echo "<br/> $errmsg <br/>";
    die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES

Open in new window

0
 

Author Comment

by:Erie_Laker
ID: 34934302
Thank you all.  Ray, I will try your script as soon as the new website becomes active (propagates) and will post results back here.
0
 
LVL 11

Assisted Solution

by:VanHackman
VanHackman earned 284 total points
ID: 34935717
>> Two domains using the same MySql database?

Yes, of course, it's completely possible!!. there is not reason for the opposite.

You should understand that under a shared hosting environment, even if you have 2, 3 or and X number of domains, all of them still being "physically" hosted on the same server, so... from your sites' point of view all of them will connect to the "localhost" and because of that, will be able to use any DB for which the DB user that you have specified in your connection script, have the permmision to use.

It's something completely different when you try to use DBs that are in a different "physicall" servers, because even when it still being possible there is some little differences in the method to use them.

So, the real question here is... Would your sites be able to share a DB without screw up the DB coherence?

Thats something that you should evaluate from your code...

Hope this helps you.

All the best,
VanHackman

0
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 284 total points
ID: 34936029
Hosting that puts their databases on other servers seem to often have restrictions on how you can access them.  If you are hosted on Godaddy, you have a choice when you set up a database to allow or prevent external access.  If you allow it then other sites can use that database.  If you don't allow it, then only the original site will be allowed to connect to it.

Hostek appears to have something similar but I don't know the details because it was a client's account, not mine.  All of their databases are on their internal network and only some can be accessed externally.  1and1 wouldn't let me access a database externally but I wasn't sure about access from multiple sites there.
0
 
LVL 5

Assisted Solution

by:RizyDeWino
RizyDeWino earned 288 total points
ID: 34937015
From you post , it look like you are hosted on cPanel server. And with hosting addon domain means its not only possible, its standard. The physical paths for domains would be :

Main Domain :  /home/CPANMEUSER/public_html/
Addon Domain : /home/CPANELUSER/public_html/addondomain
( though addon can also be setup at /home/CPANELUSER/addondomain )

For the DBs they are created as   CPANELUSER_dbname , for all main and addondomains. So any domain hosted user the same CPANELUSER can access all DB under this user.

Again for cPanel servers its Standard , you will not need to do anything extra.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question