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!
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:
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.
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.
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);
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.
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.
File Permissions: Ensure that the PHP files on the second domain have the correct permissions to be read and executed by the server.
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.
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.
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.
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.
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.