Database error after copying an existing Wordpress site

  • Hi Everyone,


    Recently, I copied an existing Wordpress website; including its underlying database.

    I then created a new DNS-domein, copied the website content to this httpdocs-root, created a new database and imported the existing database.

    The next step was adjusting the Wordpress-config file to use the newly imported database.

    In addition, modified the database table where the URL is stored.


    However - when trying to access this "new" website, it returns " Error establishing a database connection".

    When I try accessing the same database via a small php-script (see below), it returns "connected succesfully".


    The source-website is working as expected.


    What am I overlooking here?


    =====


    PHP
    <?php
        $link = mysqli_connect('<ip-address>:3306', '<database-name>', '<password>');
        if (!$link) { die('Could not connect: ' . mysqli_error()); }
        echo 'Connected successfully';
        mysqli_close($link);
    ?>

    With warm greetings,

    - Will | IT visibility

  • Hi,

    sound like a connection problem :)

    Please double check the wp-config.php especially the database server IP and the identifier – it’s almost always WP_ almost ?

    If all this does not help – backup your old WP through a plugin, create a fresh installation and import the backup.

    Best regards

  • Hey,


    What do you mean with "connection problem"?

    How differs the Wordpress connection from the php-script?


    Database server and identifier match.


    What plugin would you recommend?



    Thank you - Will

    With warm greetings,

    - Will | IT visibility

  • I am wondering that you can even connect to your db with

    mysqli_connect('<host>:<port>', '<database-name>', '<password>');

    because the syntax for mysqli_connect is:

    mysqli_connect('<host>', '<user-name>', '<password>', '<database-name>', '<port>');

  • I am wondering that you can even connect to your db with

    mysqli_connect('<host>:<port>', '<database-name>', '<password>');

    because the syntax for mysqli_connect is:

    mysqli_connect('<host>', '<user-name>', '<password>', '<database-name>', '<port>');


    I know for sure that the port number defaults to 3306.

    I'm not sure about the database name - perhaps it just connects to the database service?

    And doesn't access the database at all?

    Or connects to some "default" database?


    While writing... just tried with adding the database name and port number => same result.

    With warm greetings,

    - Will | IT visibility

  • Go to phpmyadmin in WCP and check the names of db and dbuser. (Really the same as in wp_config?) Password really correct?

    Also look into the db, if there is any content.

    Ommit the port at the host in wp_config. Use only the ip of the DB-server (not the ip of the webserver)


    EDIT:

    And better use mysqli_connect_errno() to check if the connection could be established.

  • NogNeetMachinaal

    I tried your test code - it only seems to work, but a real sql query does not work.


    Here is a full test:


    The result must be an mysqli object, not null/false.


    If this really works, it can only be a config error in wordpress. What about server log files, are there any errors listed? Enabling wordpress debug logs could be helpful aswell.


  • This php-script is giving me "bool(false)" - nothing else?

    To double-check: I get the same result on the one of the other websites => the ones that are working as expected.


    The php-script is below => looks very much the same as yours?


    With warm greetings,

    - Will | IT visibility

  • If this really works, it can only be a config error in wordpress. What about server log files, are there any errors listed? Enabling wordpress debug logs could be helpful aswell.


    The debugging showed what I was overlooking all along: used TCP-port 3360 in the config-file - no where else... :sleeping:

    Now working as expected.


    Thank you for your time and patience - Will

    With warm greetings,

    - Will | IT visibility


  • I used the wrong portnumber in the wp-config-file... :sleeping:

    With warm greetings,

    - Will | IT visibility

  • in your example script in post #1 was mysqli_select_db missing, so that you was only connecting to your db server, without selecting your db. I guess there is something wrong. so double check db user including his db permissions and db name in WCP.


    result must not be bool(false). in my example you should get something like this (in my example the db is empty, but the sql query was successful)

    If not even this simple script runs successfully, wordpress will definitely have problems with the database as well.


    Edit: ah okay, wrong port number, that's great. xD :thumbup:

  • Hi,

    sound like a connection problem :)

    Please double check the wp-config.php especially the database server IP and the identifier – it’s almost always WP_ almost ?

    If all this does not help – backup your old WP through a plugin, create a fresh installation and import the backup.

    Best regards

    You where correct - connection problem => wrong TCP-port in the wp-config-file... :sleeping: