• hello dear phpexperts,?

    i thought that during the installation process the file wp-config-sample.php? gets to?
    wp-config.php – but this is not happening.?

    Quote
    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?localhost. 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.

    guess that i have to edit all the stuff manually now..?

    i want to edit the file now and i will afterwards store it as wp_config.php on the server ab.??
    Btw:?i am still wondering why this was?not happening? so far

    additionally – i will do the following?

    [QUOTE]First thing you should do is to make sure that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.[/QUOTE]

    gem. https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/

    [CODE]
    define(‘WP_ALLOW_REPAIR’, true);

    [/CODE]

    [QUOTE]
    once you have done that, you can see the settings by visiting this page:?
    [/QUOTE]

    see here??https://www.yoursite.com/wp-admin/maint/repair.php??

    i come back and report all the findings

Viewing 8 replies - 16 through 23 (of 23 total)
  • Thread Starter say_hello

    (@say_hello)

    hello dear Autotutorial

    first of all many many thanks for this superb forum and many others work here and support so many buddies user. This is just great. A great place to exchange ideas.

    many thanks dear Autotutorial – many thanks to nobbie and all the supporter.

    the continued help and support. I am trying to figure out what has happened. on a sidenote: a big big sorry – for the bit of confusing thread-posting with the issues. I am in need of help and i try to sort out things here.

    i am tryin to understand what goes on…in order to do that i recapitulate what i have done..: – i runned two differnt versions of scripts to test the connection
    a. one with mysql and
    b. one with mysqli

    i had several results – and now i have to interpret these results correcly:
    i had very very interesting results and i need to think about them – for the sake of a better understanding:

    dear Autotutorial: regarding the issues i have – some discussion of the errors that have been encoutered

    The “no such file or directory” message is also related to trying to connect to MySQL, that is related to how the mysql functions try to connect.
    i runned the MySQLi-script and afterward i runned the MySQL-script as a “Test-The-Connection-Script” Well it is probably better to use mysqli or PDO. The regular mysql extension is no longer part of PHP. Regarding the trust of the error messages. i have one, single problem – it is that PHP cannot connect to MySQL, but the one big big question is, why i cannot connect?

    conclusio: i have to read and understand the error messages

    i have to run the testscript that is written below.

    https://www.php.net/manual/en/mysqli.connect-error.php

    well – i guess that i need to run the following command: mysqli_connect_error (PHP 5, PHP 7)
    mysqli::$connect_error -- mysqli_connect_error— Returns a string description of the last connect error

    Object oriented style

    string $mysqli->connect_error;
    Procedural style
    mysqli_connect_error ( void ) : string
    Returns the last error message string from the last call to mysqli_connect().
    

    output. string that describes the error. NULL is returned if no error occurred.

    Examples:
    Example #1 $mysqli->connect_error example

    Object oriented style

    <?php
    
    $mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
    
    // Works as of PHP 5.2.9 and 5.3.0.
    if ($mysqli->connect_error) {
        die('Connect Error: ' . $mysqli->connect_error);
    }
    ?>

    Procedural style

    
    <?php
    $link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');
    
    if (!$link) {
        die('Connect Error: ' . mysqli_connect_error());
    }
    ?>
    

    The above examples will output:

    Connect Error: Access denied for user 'fake_user'@'localhost' (using password: YES) 
    

    i need to figure out the issues.

    many many thanks for any and all help

    dear Autotutorial: i will run the script and come back and report all the findings.
    i will run all the scripts and SQL-Code that you suggested me.

    at the moment i am not in front of the computer….

    I understand that there are linguistic problems, but do I execute the query after selecting the database in phpmyadmin? obviously the user jo is interested.

    Thread Starter say_hello

    (@say_hello)

    hello dear Autotutorial

    first of all – many many thanks for the continued help and support. I am trying to figure out what has happened. And for the phpmyadmin – i have a similar tool that is integrated in the Webadmin-frontend that looks like a small and tiny phpmyadmin-fronetend. There i perfom some SQL-commands.

    i also did some tests.

    
    
    <?php
    $mysqli = new mysqli('localhost', 'jo', 'susi19', 'jo');
    
    /*
     * This is the "official" OO way to do it,
     * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
     */
    if ($mysqli->connect_error) {
        die('Connect Error (' . $mysqli->connect_errno . ') '
                . $mysqli->connect_error)
    }
    
    $mysqli->close();?
    
    ?>
    

    then i get back

    Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /sites/www.my_page.org/new_test.php on line 2
    Connect Error (2002) No such file or directory

    some more ideas that i need to think about.?

    i should do some more tests and i will try to change?“localhost” to “127.0.0.1

    cf: https://www.fatalerrors.org/a/warning-mysqli-mysqli-hy000-2002-no-such-file-or-directory.html

    i further have to test??[url=”https://www.dreamincode.net/forums/topic/214733-introduction-to-pdo/”%5DPDO%5B/url%5D it is told to be much easier to deal with than MySQLi.

    what i need to do.

    a. i will try the changing “localhost” to “127.0.0.1”
    b. i have no experience with PDO but i will dig deeper into all that. I am going to read the docs. ?

    above all: well – this is so crazy and i think that there some kind of magic things are happening.

    btw: many of the wordpress-experts here told me that i should not use 127.0.0.1 instead of localhost for the servername.?

    But while is constantly going wrong and does not work at all i am musing about using 127.0.0.1 instead of localhost as the server name.

    Besides that i think that there might be some more issues:
    i have to do some more checks:

    – is there probably some firewalls in between the MySQL process and the network-stack and if it isn’t that,
    – i might have a closer look at the editing of mysqli.default_socket in php.ini and i need to check that the
    path is set correct.

    the next things i will have to do:?
    i do the change of “localhost” to “127.0.0.1”
    and report all the findings.?

    Autotutorial – Do you have and additional ideas what i can do and test!??
    above all i am so glad that you do such a great support here. I am overwhelmed by your continued help.

    keep up the great job – it rocks!!!!

    Thread Starter say_hello

    (@say_hello)

    hello dear all, hello dear Autotutorial.

    well – first of all many many thanks for the continued help and support. I am trying to figure out what has happened. i am very glad to be here on this great place.?
    a big big sorry – for the bit of confusing thread-posting with the issues. I am in need of help and i try to sort out things here.

    Well after futher tests i am pretty clueless.

    some first statements:?

    i am on PHP Version 5.6.39

    btw: I have Linux Server – based on opensuse:?

    Apache 2.4.10, PHP Version 5.6.39 and
    mysqlnd 5.0.11-dev – 20120503?
    the newest version of Webadmin – Webmin 1.910
    see https://www.webmin.com/

    i have testesd varios versions of the mysqli.connect-error-scripts…

    see the results i have gathered:?

    see the idea – and the code: https://www.php.net/manual/en/mysqli.connect-error.php

    mysqli::$connect_error
    mysqli_connect_error
    (PHP 5, PHP 7)

    Example #1 $mysqli->connect_error example

    Object oriented style

    
    <?php
    $mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
    
    // Works as of PHP 5.2.9 and 5.3.0.
    if ($mysqli->connect_error) {
    ? ? die('Connect Error: ' . $mysqli->connect_error);
    }
    ?>
    

    i also runned the prozedural-style?

    
    <?php
    $link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');
    
    if (!$link) {
    ? ? die('Connect Error: ' . mysqli_connect_error());
    }
    ?>
    
    

    and got back the following: Connect Error: No such file or directory
    note: i also runned this with the adviced replacement of localhost with 127.0.0.1? … see below:?

    
    <?php
    $link = @mysqli_connect(''127.0.0.1'', 'user', 'db-passwd', 'db-name');
    
    if (!$link) {
    ?die('Connect Error: ' . mysqli_connect_error());
    }
    ?>
    
    

    and i got back here: Connect Error: No such file or directory
    …and here we have more insights? – i also runned the?PDO-version:?

    see: https://www.w3schools.com/php/php_mysql_connect.asp

    
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    
    try {
    ?$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
    ? ? 
    // set the PDO error mode to exception
    ? ? $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    ? 
    
    ? echo "Connected successfully";?
    ? ? }
    catch(PDOException $e)
    ? ? {
    ?echo "Connection failed: " . $e->getMessage();
    
    ? ? }
    ?>
    
    

    see what i have got back:

    Connection failed: SQLSTATE[HY000] [2002] No such file or directory

    Note: In the PDO example above we have also specified a database (myDB). PDO require a valid database to connect to. If no database is specified, an exception is thrown.
    Tip: A great benefit of PDO is that it has an exception class to handle any problems that may occur in our database queries. If an exception is thrown within the try{ } block, the script stops executing and flows directly to the first catch(){ } block.

    cf. https://www.w3schools.com/php/php_mysql_connect.asp

    conclusio: all attemts to set up a mysql-db that is accessible from a WordPress-installation failed.

    some more ideas that i need to think about.?
    i should do some more tests and i will try to change “localhost” to “127.0.0.1
    see https://www.fatalerrors.org/a/warning-mysqli-mysqli-hy000-2002-no-such-file-or-directory.html

    i further have to test ?[url=”https://www.dreamincode.net/forums/topic/214733-introduction-to-pdo/”%5DPDO%5B/url%5D it is told to be much easier to deal with than MySQLi.

    what i need to do:

    a. i also have tried the changing “localhost” to “127.0.0.1”
    b. i have no experience with PDO but
    i will dig deeper into all that. I am going to read the docs.?But see – i allready have done a first test with PDO?

    above all: well – this is so crazy and i think that there some kind of magic things are happening.

    i have to do some more checks:
    – is there probably some firewalls in between the MySQL process and the network-stack and if it isn’t that,
    – i might have a closer look at the editing of mysqli.default_socket in php.ini
    and i need to check that the path is set correct.

    i need to do more tests and report all the findings.

    but at the moment i am a bit clueless…
    ?

    What can i do now!??

    from php 7.1 wordpress only supports the mysqli library.
    You have to modify your confuguraziine mysql the problem is there.

    Modify the MySQL configuration file my.cnf to specify the location of the mysql.socket:

    /var/lib/mysql/mysql.sock (your mysql.socket path).

    Specify the location of my.socket directly when the connection is established in PHP (official document: mysqli_connect). Such as:

    $db = new MySQLi(‘localhost’, ‘root’, ‘root’, ‘my_db’, ‘3306’, ‘/var/lib/mysql/mysql.sock’)

    maybe 'localhost:/var/liv/mysql/mysql.sock'
    if php and mysql are installed on different machines it can never be localhost.

    Thread Starter say_hello

    (@say_hello)

    hello and good eveing dear Autotutorial

    mmm – this allmost is a issue for more than 2 Weeks now! I guess that you are right. This seems to be an issue that is rooted in some configs…

    first of all many many thanks to you dear Autotutorial – you are just great and you do a superb job here on the wordpress-site: I am overwhelmed by your continued help and support. Dear Autotutorial – a big big sorry – for the bit of confusing thread-posting with the issues. I am in need of help and i try to sort out things here.

    again: this error is quite very hard to fix .? i re-checked some tests and the behavior of the server while running the following scripts?

    
    define("HOST",'localhost');
    define("USERNAME",'jc');
    define("PASSWORD",'my_passwd');
    
    ? ? $db = new PDO("mysql:host=".HOST,USERNAME,PASSWORD);
    ? ? $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    ? ? $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    ? ? $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    
    $res = $db->query("SELECT 7 * 6 ");
    echo $res ->fetchColumn(); ? ? ? ? ?//--> 42

    …throws back the following:?

    
    define("HOST",'localhost'); define("USERNAME",'jc'); define("PASSWORD",'my_secret_passwd'); $db = new PDO("mysql:host=".HOST,USERNAME,PASSWORD);?
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);?
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);?
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);?
    $res = $db->query("SELECT 7 * 6 ");?
    echo $res ->fetchColumn(); //--> 42
    

    and the following script?

    
    
    <?php
    $servername = "localhost";
    $username = "jc";
    $password = "my_passwd";
    
    try {
    ? ? $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
    ? ? // set the PDO error mode to exception
    ? ? $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    ? ? echo "Connected successfully";?
    ? ? }
    catch(PDOException $e)
    ? ? {
    ? ? echo "Connection failed: " . $e->getMessage();
    ? ? }
    ?>
    

    …throws back the following:

    
    Connection failed: SQLSTATE[HY000] [2002] No such file or directory
    

    ?

    I spend some time in trying to find out what goes wrong here: – see what i have? found out: ….?

    ?Connection failed: SQLSTATE[HY000] [2002] No such file or directory ….. what means according this hread: /strong>??https://stackoverflow.com/questions/29695450/pdoexception-sqlstatehy000-2002-no-such-file-or-directory

    Quick test (run in shell):

    
    php -r "new PDO('mysql:hostname=localhost;dbname=test', 'username', 'password');"
    
    

    ?

    ?see the following: `

    SQLSTATE[HY000] [2002] No such file or directory means php cannot find the mysql.default_socket file. Fix it by modifying php.ini file. On Mac it is mysql.default_socket = /tmp/mysql.sock (See PHP – MySQL connection not working: 2002 No such file or directory)? SQLSTATE[HY000] [1044] Access denied for user ‘username’@’localhost’ CONGRATULATION! You have the correct mysql.default_socket setting now. Fix your dbname/username/password. `

    Also see Error on creating connection to PDO in PHP ( cf: https://stackoverflow.com/questions/1435445/error-on-creating-connection-to-pdo-in-php )

    Today, I removed and reinstalled the latest version of lampp in order to move to php 5.30, and suddenly a very simple app?is failing to connect to the mysql database. I’m using PDO to connect, and receiving the following error:

    ?Warning: PDO::__construct() [pdo.--construct]: [2002] Invalid argument (trying to connect?via unix://) in /home/raistlin/www/todoapp/home.php on line 9 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002]

    [.. and so forth and so forth..]?

    ….. see some answers that i have found for the cumbersome issues:?

    answer1:
    Usually means that you need to specify TCP/IP (1), or tell MySQL where your Unix socket is (2):

    
    "mysql:host=127.0.0.1" or "mysql:host=localhost;port=3306"
    "mysql:unix_socket=/var/run/mysqld/mysqld.sock"
    

    answer2: ?

    You can also use 127.0.0.1, rather than specifying “localhost”, in your db connection string to avoid this issue altogether.

    answer3:

    You might want to modify php.ini so PDO can find mysql.sock by specifying the pdo_mysql.default_socket = /opt/lampp/var/mysql/mysql.sock (in the case of xampp). Don’t forget to restart Apache after changing php.ini.

    cf: https://stackoverflow.com/questions/1435445/error-on-creating-connection-to-pdo-in-php

    well i think i have some issues on my server…?

    dear Autoturorial – i think that you are 100 right – and that you show into the right direction – i guess that it is time to discuss all that with the serveradmin – since he is the guy that can change the configs…

    Thread Starter say_hello

    (@say_hello)

    Hallo dear Autotutorial

    now it works … ??

    first and above of all – many many thanks for your help and your replies. i am very glad to be here on this great place at www.ads-software.com.

    Wordpress is such a great experience and it lives through its great user, developer and supporter-base: this is just a great experience and i am glad for that.

    Dear Autotutorial: – many many thanks for the continued help and the your support. Thanks for not letting me down. i have encountered this for many years now here at wordpress. You and many others here do such a great job here. And this is just great and a really overwhelming experience. i am very very happy that you never have gave up the support and the continued help here at www.ads-software.com

    Note: the wordpress-user like me – who are not as experienced – all of us are so glad that this community has got such a great support!

    Now it works – i have talked to my serveradmin and he did some corrections. And now all runs like a chame. Note: i will talk to him and will ask him what exactly he did – in order to get to know what was the missing piece. I come back later the week and will let you know!!! I need to learn from this thing – !!!


    Above all
    : Keep up the great work it rocks.

    have a great day!!!!!!

    PS – WordPress is one of the best experiences i made – it is so great!!!

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Error establishing database connection – how to proceed now’ is closed to new replies.