Report this

What is the reason for this report?

Two domains using same mqsql database

Posted on April 25, 2015

I have two domains using the same droplet and same mysql database. The data is fetched and displayed fine for the first domain, but, the second domain doesn’t show any data.

Connecting to database and selecting the database is happening, but, the page (for the second domain) doesn’t display any data. What could possibly be the problem? Please help. Thanks.

<?php

$link = mysql_connect('localhost', 'username', 'passowrd') or die(mysql_error());
if ($link) 
{
echo ('Connect susscufully ..... and ...... '); 
} 
else 
echo ('Not connect');

mysql_select_db('enarexperts',$link) or die(mysql_error());
echo "Connected to Database";
?>


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Yes, same MySQL user and same code for both domains. I even tried to create a new mysql use and grant access, same result. I can connect to mysql database via putty fine.

The issue you’re facing with your second domain not displaying data, despite using the same droplet and MySQL database as the first domain, could be due to a variety of factors. Here are some possible causes and troubleshooting steps:

  1. Database Connection Credentials: Double-check the credentials (username, password, database name) used for the connection. They should be identical for both domains if they’re accessing the same database.

  2. Database User Permissions: Ensure that the MySQL user specified in your connection string has the necessary permissions to access and query the database from the second domain.

  3. PHP Error Reporting: Enable PHP error reporting to see if there are any warnings or errors that aren’t immediately visible. You can enable error reporting by adding the following lines at the beginning of your script:

error_reporting(E_ALL);
ini_set('display_errors', 1);
  1. SQL Query Execution: Check if you’re executing any SQL queries after connecting to the database. If so, ensure they are being executed correctly. Use mysql_error() to print any errors related to SQL queries.

  2. PHP Script Differences: If there are differences in the PHP scripts between the two domains, even small ones, they could lead to different behaviors. Review the code on the second domain to ensure it’s intended to fetch and display data.

  3. File Permissions: Ensure that the PHP files on the second domain have the correct permissions to be read and executed by the server.

  4. Server Configuration: There might be differences in server configuration (like .htaccess files, Apache or Nginx configurations) between the two domains. These could affect how PHP scripts are executed.

  5. DNS and Server Cache: Sometimes, issues can be related to DNS or server caching. Clearing the cache or waiting for DNS propagation (if there have been recent changes) might resolve the issue.

  6. Database Table Structure: Ensure that the database table structure is compatible with the queries in your PHP script. If there were recent changes to the database, they might affect how data is fetched and displayed.

  7. Cross-Domain Issues: If the script is making any cross-domain requests (for example, fetching data from a domain different from where the script is hosted), ensure there are no cross-domain policies (like CORS) preventing the data from being fetched.

  8. Network Issues: Rarely, the issue could be due to network problems between your server and the database. Check if there are any network connectivity issues.

As a best practice, consider moving away from the deprecated mysql_* functions and use mysqli or PDO for database interactions in PHP. This not only improves security but also provides better error handling and debugging capabilities.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.