Error establishing database connection

Discussion in 'Troubleshooting' started by alverdeja, Apr 3, 2015.

  1. alverdeja

    alverdeja New Member

    Joined:
    Sep 18, 2012
    Messages:
    18
    Hi,
    I'm receiving an "Error establishing database connection" error when I try to access any aMember integrated files or pages, including the aMember Admin CP. I am running aMember 4.2.x in conjunction with WP.

    I wasn't making any drastic changes when I began receiving the error and like others who experienced the same problem, I wasn't upgrading PHP.

    After reading other threads where users had the same problem, I changed my DB user passwords for both my aMember and WP databases and in their respective config.php files, but I'm still getting the error.

    Anyone have any ideas? Thanks in advanced!
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    So you started getting error message after making changes. What were those changes as that could be instrumental in finding solution?

    Error log messages?
  3. alverdeja

    alverdeja New Member

    Joined:
    Sep 18, 2012
    Messages:
    18
    I'm pretty sure I had just selected the checkbox to use WordPress themes or something similar in the WP integration section of the Config page.
  4. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Presume you have tried setting checkbox back.

    Can you log into aMember successfully?

    Do you have cPanel on your server? Try accessing aMember and then go to cPanel error logs page and copy and past relevant error message as it could give a good indication of where problem lies, such as aMember or Wordpress databases, username or password problem and also if being addressed with correct host details.
    PHP:
    <?php
    // Database details
                
    $db    '';
                
    $user  '';
                
    $pass  '';
                
    $host  'localhost';
                
    $prefix 'am_';
                
    $port  '';

    //Database access test
         
    $dsn 'mysql:dbname='.$db.';host='.$host;
              
         try {
      
    $db_conn = new PDO($dsn$user$pass);
    } catch (
    PDOException $e) {
      echo 
    "Could not connect to database";
      }
      echo 
    '<br>';
      echo 
    'V1.00<br>';     
      echo 
    'Bye';          
                
    ?>
    Try adding your database name, username and password to the above code and then saving it as 'access_test.php for example.

    Now upload it to your server and try accessing it from a browser. Screen should simply say 'V1.00' and 'Bye'.
    If it also says 'Could not connect to database' then some of the details entered were incorrect in some way.
  5. alverdeja

    alverdeja New Member

    Joined:
    Sep 18, 2012
    Messages:
    18
    Unfortunately, I can't login to my aMember CP. Actually, I can't access anything in my server's /amember directory without receiving the "Error establishing database connection" error.

    Is there somewhere specific on my server that I should upload the access_test.php file? I tried placing it in the /amember folder, but still got the same old "Error establishing database connection". :`(
  6. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Outside aMember in root directory.

    Above script simply needs the database_name, username and password of the database. It doesn't interact with aMember at all.

    If it connects with the database then aMember should be able to also unless, of course, when you changed the password in config.php you inadvertently changes something else as well.

    Contents of config.php
    PHP:
    return array(
        
    'db' => array(
            
    'mysql' => array(
                
    'db'    => '',
                
    'user'  => '',
                
    'pass'  => '',
                
    'host'  => 'localhost',
                
    'prefix' => 'am_',
                
    'port'  => '',
            ),
        ),
    );
  7. alverdeja

    alverdeja New Member

    Joined:
    Sep 18, 2012
    Messages:
    18
    I ran it and the browser displayed V1.00 bye. So I guess aMember should be able to connect to the DB. the passwords for the DB and in the config.php should be identical as I literally changed them both withing a minute of each other. Also, I didn't alter anything else on the config.php file or to the database(knowingly at least).

    Also, I want to say thank you thehpmc very much for all of the help you've given me so far! Even though my problem is unresolved, you've been a great help!
  8. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Post up, or PM me if you prefer, a copy of your config.php file also pm copy of the script I sent so I can compare details and I'll see if there is anything obvious.

    Just a thought also change username or password in script and test with that. Just to make sure it then cannot connect to database but send me correct version.

    Another thought did you try disabling Wordpress so its database details is checked and did you think to run test script but with the Wordpress database details?
  9. alverdeja

    alverdeja New Member

    Joined:
    Sep 18, 2012
    Messages:
    18
    I was able to get everything working, but only after restore my entire site from a earlier backup.

    I can shed some light now on what may have caused it. After looking at the aMember CP, I remember that I selected the "Enable Wordpress Network Support" checkbox in the WP integration config page right before I began receiving the error. I did this because I thought it might be why I had been having some protection problems and because I'm running WP Multisite. I don't fully understand why it completely broke my site, however.

    Anyways, thank you THEHPMC for all your help!
  10. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Thanks for the feedback and glad everything working ok now.

    I don't run Wordpress on my site so have VERY little knowledge on it so cannot offer any suggestions why it broke your site.

Share This Page