WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Error establishing database connection (15 posts)

  1. CallMeAndy
    Member
    Posted 1 year ago #

    I am in the process of trying to migrate a local development of a wp multisite buddypress implementation to a remote test site on the same server that production will be housed (this is at hostgator)

    Getting the "error establishing a database connection error" on trying to access the domain through the browser.

    although i overlooked the advice here:
    http://codex.wordpress.org/Moving_WordPress#Moving_WordPress_Multisite
    before starting the operation

    and as a consequence have not edited the post data or other options data than these:
    home
    siteurl
    fileupload_url

    Although I dont see why this should effect the connection (maybe a misleading message) so was going to try to debug the remote code execution with PhpEd but this has presented other issues which I wont distract with here.

    .htaccess has been retained from a working prior development iteration, on the remote server - it was working previously and the site structure has not changed between iterations.

    I have edited wp-config to correct database credentials.

    this is confirmed by use of the database connection tests script at http://gist.github.com/162913.txt
    mentioned on this page
    http://codex.wordpress.org/User:Sivel/FAQ
    Which says all is good to go.

    Yet still the error message.

    Anybody help on this?

  2. WebTechGlobal
    Member
    Posted 1 year ago #

    Can we rule out your hosting package being brand new within the last couple of hours of when this happened? Just sometimes hosting is not fully ready to go straight away.

    You said your database credentials are correct. Can you confirm that is while looking at the wp-config.php file on your live server and not locally.

    Easy to make that mistake of thinking you have uploaded it, even many times. Yet you realize your FTP is failing, after posting for help. Yes I've done that in the early days :)

  3. CallMeAndy
    Member
    Posted 1 year ago #

    Yes rule that out its not a live site yet but the package has been running error free for a couple of months.

    Yes the remote credentials are different to the local and have been changed and verified. Also as confirmation presumably the db test script uses the credentials in wp-config to access the database as I did not have to provide any. I didnt physically look through the script.

    wp_config is definitely changed remotely verified by making changes and reopening therafter. So FTP is not the issue.
    Thanks for getting back to me.

  4. CallMeAndy
    Member
    Posted 1 year ago #

    I dont know if it's led this thought process astray but in the original remote wp-config.php I did have:
    define('SUBDOMAIN_INSTALL', true);
    (this was the working state of the previous iteration)

    Which I changed to false as I read that this might solve the problem where I was getting redirected thus:
    http://adventurebod.com/wp-signup.php?new=adventurebod.com
    and the error message:
    "The page isn't redirecting properly"

    Well the problem did solve the redirect but gavve me the database issues.
    The remote server has PHP 5.3.15
    on the local deve platform its 5.3.6
    I take it this should not cause any problem.

    The local MySql may have some sort of issue with it though I dont think it would have any effect on the remote once data is imported apparently without fault.
    Remote server shows 5.5.23 in both phpmyadmin and info.php
    Local server shows 5.5.13 in phpmyadmin
    5.08 on info.php (this seems a bit strange)

    Obviously I am picking straws in the hope that something twigs with someone.

    Anybody got any other suggestions?

  5. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    I have edited wp-config to correct database credentials.

    Check it again and see that you have entered the correct DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.

  6. CallMeAndy
    Member
    Posted 1 year ago #

    Man do I feel confused - not sure how I did that but at some point I must have reset the DB_HOST to localhost.

    However the output is now different but perhaps the underlying problem is unchanged, largely because I changed: define('WP_DEBUG', true); from false, to see if I got any further pointers.

    Also where I mentioned earlier that the remote PHP is v 5.3.15 it had only been so for 15 mins since upgrading the hostgator version from 5.2.xx
    Though I was not expecting a delay and testing it shortly before the last message in this thread showed no difference.

    Anyway the output now is:

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'andyseab_abtest1'@'gator408.hostgator.com' (using password: YES) in /home/andyseab/public_html/adventurebod.com/wp-includes/wp-db.php on line 1038

    Error establishing a database connection

    This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at adventurebod.com. This could mean your host's database server is down.

    Are you sure you have the correct username and password?
    Are you sure that you have typed the correct hostname?
    Are you sure that the database server is running?

    If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

  7. CallMeAndy
    Member
    Posted 1 year ago #

    I should also point out that I did verify again the database user credentials on db and reset the password to what I thought it should have been, I am sure in reality it has not changed, either way this is not resolving anything. I dont know how common this is but the usual users table you would in phpmyadmin is witheld on hostgator and presented under their own interface.

    Andy

  8. Krishna
    Volunteer Moderator
    Posted 1 year ago #

    I still feel that it is incorrect settings of wp-config.php. Anyway, did you seek support from your hosting company for this, especially in view of the their own interface that is withheld? If not, please contact your host.

  9. CallMeAndy
    Member
    Posted 1 year ago #

    OK I will check with the hosting provider but I am not sure if this is really a database problem or not.

    I probably need to get some sleep and put a fresh mind on it tomorrow but I have just looked back the previous iteration which was working and in fact DB_HOST was definitely set to localhost previously.

    So I have put it back to localhost.

    and it had this directive set:
    define('MULTISITE', true);

    So I have put that back as it was but this is position is not giving me a databse error but the redirect I mentioned.

    that is:
    http://adventurebod.com/wp-signup.php?new=adventurebod.com
    and the error message:
    "The page isn't redirecting properly"

    Apart from anything it seems like the original scenario will be the best starting point tomorrow as I have definitely confused myself tonight.

  10. WebTechGlobal
    Member
    Posted 1 year ago #

    You mentioned PHP versions both local and server.

    If you connect your local installation of WordPress to your database hosted with, hostgator I think it was. PHP on hostgator is not used in the process. phpmyadmin on hostgator end is not used in any way, so you can ignore all that.

    A good way to solve this issue is install WordPress on your hosting. Fresh new installation including a new database. Then switch THAT installation over to the database your trying to connect your local WordPress to. See what happens.

    Then compare your local wp-config.php files with those online. I'm going to guess no difference, you know enough. However when your troubleshooting goes on this long its good to keep ruling things out.

    After doing this you may be more encouraged to contact hostgator and ensure connection is not being blocked.

    I must say, it has been over a year since I worked locally. So I'm hoping I'm not missing out something myself. define('DB_HOST', 'localhost'); is usually what trips people up.

    I'm a co-author with CSV 2 POST and Easy CSV Importer. We find huge advantages to working online, including being able to let other developers quickly access the nightly build without the admin of uploading it. Which is small, until your doing it every day for years.

  11. CallMeAndy
    Member
    Posted 1 year ago #

    Hi WebTechGlobal:

    If you connect your local installation of WordPress to your database hosted with, hostgator I think it was. PHP on hostgator is not used in the process. phpmyadmin on hostgator end is not used in any way, so you can ignore all that.

    I am not getting what you mean here. I take it you mean providing the remote database to local development, but I still have to face issues with hostgators configuration to implement builds. Although I do see some convenience in this approach. Purely working online doesnt seem possible at this stage at least not with PhpEd the IDE I usually use. I think its capable but supposedly I can only embed remote debugger on a VPS environment or dedicated seat.

    A good way to solve this issue is install WordPress on your hosting. Fresh new installation including a new database. Then switch THAT installation over to the database your trying to connect your local WordPress to. See what happens.

    Do you mean upload the dump from local and put it on the remote? This is only the same as what I am doing now before upoading the dump on to the remote datasbe I am dropping all tables - its an empty core. The validity of the data should not effect being able to connect to it. Or is there something I'm missing?

    Then switch THAT installation over to the database your trying to connect your local WordPress to.

    I dont have a problem connecting local dev to local database.

    Then compare your local wp-config.php files with those online. I'm going to guess no difference, you know enough. However when your troubleshooting goes on this long its good to keep ruling things out.

    The only difference I think would be the fact that my local wp-config would already be set for multisite. Assuming you meant set that first, I would be back with the same wp_config I have now. Before I started this process I copied the wp-config from the "working" installation. That said there maybe nothing else I can do, but to do this tomorrow, as the first part of what looks like a rebuild online. God thats a lot of work, luckily I had the foresight to pretty thouroughly document it. Still its a headache coming and I need to resolve the cause as I cant afford the overhead of this every iteration.

    After doing this you may be more encouraged to contact hostgator and ensure connection is not being blocked.

    Surely if I can use phpmyadmin without issue the connection is not blocked.

  12. WebTechGlobal
    Member
    Posted 1 year ago #

    Sorry did you mean your using phpmyadmin locally on your hostgator database? I didn't take that in sorry. Yes that rules out hostgator server security getting in the way.

  13. CallMeAndy
    Member
    Posted 1 year ago #

    No

    Local setup = development environment WAMP and phpmyadmin. This install of phMyadmin only connecting locally

    Remote setup = No dev, LAMP cPanel and phpmyadmin. Using this install of phpMyadmin only to connect within the remote environment

    I wonder if you see it differently the way i have left things at the moment is with:

    define('SUBDOMAIN_INSTALL', false);

    which seems logical as this is a subdirectory implementation, unyet the original configuration read true and was created by WP autmotically. Right now niether value is redirecting which is strange as I am sure changing this value was switching back and forth between redirect and connection issues. But I am getting tired and really need to go to bed.

    Thanks for you help so far.

  14. CallMeAndy
    Member
    Posted 1 year ago #

    Right a new day! The message must be a misnomer.
    It is a a fact that the very simple db check script that I mentioned runs from the credentials in wp-config.php and it is able to list the tables so therfore there is a connection.

    I put some output debug statements in the code to try and see whats going on on the remote:

    In the code for ms-settings.php we have:

    if ( ! defined( 'WP_INSTALLING' ) ) {
    ...
           if ( ! $current_blog || ! $current_site ){
                if ($current_blog ){
                    echo '$current_blog =';
                    print_r($current_blog);
                }
                if ($current_site){
                    echo('
                    $current_site = ');
                    print_r($current_site);
                }
    	    ms_not_installed();
            }
    ...

    this was the resulting output prior to database connection error output.

    $current_site = stdClass Object ( [id] => 1 [domain] => adventurebod.com [path] => / [blog_id] => 1 [cookie_domain] => adventurebod.com )

    So it seems $current_site is instantiated and $current_blog is not
    I put in the output lines to try and see why ms_not_installed() was being triggered, as this is the function that is killing the process. You can look at that yourself but its not a decision making function, principly it just formats the database error message and then dies:

    if ( ! is_admin() )
    die( $msg );

    is_admin is declared thus:

    function is_admin() {
    	if ( defined( 'WP_ADMIN' ) )
    		return WP_ADMIN;
    	return false;
    }

    I can only see WP_ADMIN defined in two likely files (although there are two unlikely from the file names) and for both of them comments in the code say that we are in an admin screen. Which we are not so it seems once execution reaches ms_not_installed in this case with unequal blog and site objects - its all over.

    Obviously I still need to delve and see what should determine the $current_blog -- it appears that hasnt happened, and I wonder if an assumption has crept into the code that this means a failed connection.

  15. CallMeAndy
    Member
    Posted 1 year ago #

    Got to the bottom of it - I dont read what is writtain I merely assume I have!!!

    As I suspected there was a connection active. Credentials were always correct. So two things led me astray, the first the inappropriate error message. THe second the readin error that I mentioned.

    In the section Moving WordPress Multisite in the text at http://codex.wordpress.org/Moving_WordPress#Moving_WordPress_Multisite
    It says this:

    If you're moving Multisite from one folder to another, you will need to make sure you edit the wp_blogs entries to change the folder name correctly. You should manually review both wp_site and wp_blogs regardless, to ensure all sites were changed correctly.

    The opening line threw me off course thinking the paragraph was about folder moves only, so I must have only scanned what was there and didnt realise I needed to fix the wp-blogs table, but then why would I think that was an issue if there was not yet a database connection!! Ha ha!

    Unfortunatly I spent a load of time debugging the remote install with print_r and echo statements embedded all over the place so I could trace the execution. As you can see below, included for posterity in case anyone is intreested in how you might troubleshoot problems (reading the bloody manual would be a better idea though). The clue I should of seen quicker and I put down to lack of WP experience or knowledge was the get_blog_details() call - which when you look at the code in ms-blogs.php its is quite clear there is already a database connection, and analysing the sql statements enables you to see what data might be missing - of course all my blogs were still showing localhost.

    After that for anyone looking for a quick passage to getting your data in shape try the searchandreplacetool

    Saved me ages. Particularly in relation to post data.

    Anyway thanks for your time guys,
    a sounding board always help.

    So for posterity and anyone wanting to debug remotely here is an example - which is no doubt totally worst practice but will get you there!-------
    Actually $current_blog was derived just a few lines above in ms-settings.php
    I put the debug lines in the code below but to be frank I am not sure

    if ( is_subdomain_install() ) {
    ...
    }else{
         $blogname = htmlspecialchars( substr( $_SERVER[ 'REQUEST_URI' ], strlen( $path ) ) );
    
            if (defined('WP_DEBUG')){
                echo '
                $_SERVER[ "REQUEST_URI" ] ="';
                print_r($_SERVER[ 'REQUEST_URI' ]);
                echo '"';
            }
    
    		if ( false !== strpos( $blogname, '/' ) )
    			$blogname = substr( $blogname, 0, strpos( $blogname, '/' ) );
    		if ( false !== strpos( $blogname, '?' ) )
    			$blogname = substr( $blogname, 0, strpos( $blogname, '?' ) );
            if (defined('WP_DEBUG'))
                echo '
                $blogname ='.$blogname;
    		$reserved_blognames = array( 'page', 'comments', 'blog', 'wp-admin', 'wp-includes', 'wp-content', 'files', 'feed' );
    		if ( $blogname != '' && ! in_array( $blogname, $reserved_blognames ) && ! is_file( $blogname ) )
    			$path .= $blogname . '/';
    
            if (defined('WP_DEBUG'))
                echo '
                $domain = '.$domain.' $path ="'.$path.'"';
    
    		$current_blog = wp_cache_get( 'current_blog_' . $domain . $path, 'site-options' );
    
            if (defined('WP_DEBUG')){
                echo '
                $current_blog(1)=';
                print_r($current_blog);
            }
    
    		if ( ! $current_blog ) {
    			$current_blog = get_blog_details( array( 'domain' => $domain, 'path' => $path ), false );
                if (defined('WP_DEBUG')){
                    echo '
                    $current_blog(2)=';
                    print_r($current_blog);
                }
    			if ( $current_blog )
    				wp_cache_set( 'current_blog_' . $domain . $path, $current_blog, 'site-options' );
    		}
    		unset($reserved_blognames);
    	}

    The output from this was

    $_SERVER[ "REQUEST_URI" ] ="/"
    $blogname =
    $domain = adventurebod.com $path ="/"
    $current_blog(1)=
    $current_blog(2)=
    $current_site = stdClass Object
    (
    [id] => 1
    [domain] => adventurebod.com
    [path] => /
    [blog_id] => 1
    [cookie_domain] => adventurebod.com
    )
    <h1>Error establishing database connection</h1>

Topic Closed

This topic has been closed to new replies.

About this Topic