Solved

Two domains using the same MySql database?

Posted on 2011-02-19
8
414 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
8 Comments
 
LVL 4

Accepted Solution

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

Assisted Solution

by:PhSyChoTiK
PhSyChoTiK earned 72 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 71 total points
ID: 34933996
I think I once tried it works successfully on a Linux Hosting with CPanel.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 71 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 71 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 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 71 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 72 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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