check the settings of the mysql-db that runs remotely we can

Seit kurzem gibt es Webmin als erstes experimentelles Add-on zu LAMPP. Hier geht es um die Erfahrungen mit diesem Zusatzmodul oder aber auch generell um Webmin.

check the settings of the mysql-db that runs remotely we can

Postby unleash_it » 08. June 2019 00:38

if we want to check the settings of the mysql-db that runs remotely we can create a script like so:
Code: Select all
    <?php
    if(function_exists('mysqli_connect')){
    if(!($link = mysqli_connect('localhost','user-name','passwd','db-name'))){
    die('could not connect: ' . mysqli_error($link));
    }
    } else {
    die("don't have mysqli");
    }
    echo 'connect successfully';
    mysqli_close($link);

if we get back the following results does this mean that we have chooooosen the wrong path to db-pipe!?

Code: Select all
    Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /sites/www.mysite.de/testconnection.php on line 3
    Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in /sites/www.mysite.de/testconnection.php on line 3
    Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /sites/www.mysite.de/testconnection.php on line 4
    could not connect:


unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby Nobbie » 08. June 2019 21:09

You say, your mysql-db runs "remotely" (whatever is meant by that), but instead you provide "localhost", what is weird, as "localhost" never ever runs "remotely".
Nobbie
 
Posts: 11214
Joined: 09. March 2008 13:04

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 09. June 2019 15:23

hello again dear nobbi
thanks for the quick reply


agaiin - tbe server is nnot here at home - it is in the hosting center - far from home... away
meanwhile i have tried to install wp on a rootserver that is administrated by my friend i have got issues while trying to establish a db connection.

then i tried to run a test-teh connection script which gives back the following results


Code: Select all

    Warning: mysqli_connect(): (HY000/2002): No such file or directory in 
    /sites/www.mysite.de/testconnection.php on line 2
    Warning: mysqli_error() expects exactly 1 parameter,
    0 given in /sites/www.mysite.de/testconnection.php on line 4
    Could not connect:




well - what does this script-results say - do i have issues and errors in the path of the pipe!?do i have to do corrections here

Code: Select all
     * For information on other constants that can be used for debugging,
     * visit the Codex.
     *
     * @link https://codex.wordpress.org/Debugging_in_WordPress
     */
    define( 'WP_DEBUG', false );
    
    /* That's all, stop editing! Happy publishing. */
    
    /** Absolute path to the WordPress directory. */
    if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );
    }
    
    /** Sets up WordPress vars and included files. */
    require_once( ABSPoH . 'wp-settings.php' );




agaiin - tbe server is nnot here at home - it is in the hosting center - far from home... away

well -
i am musing what is going on here
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 09. June 2019 23:16

update - update - i have gathered some more insights :
i have gathered some more infos and insights due to some more tests.


see the following data: - the outcome of a testscript:

Code: Select all
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /sites/www.mysite.de/tests.php on line 3
Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /sites/www.mysite.de/tests.php on line 4 could not connect


see the script:



Code: Select all
<?php
if(function_exists('mysqli_connect')){
if(!($link = mysqli_connect('localhost','user','passwd','my_db'))){
die('could not connect: ' . mysqli_error($link));
}
} else {
die("don't have mysqli");
}
echo 'connect successfully';
mysqli_close($link);


some ideas:

the paths seem to be a problem - in the config
by the way: the character-code is 1252 ANSI L

any idea and help - i look forward to hear from you

regards
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 10. June 2019 22:23

on a sidenote,. ...

regarding the errormessage

Code: Select all

1 Warning: mysqli_error() expects exactly 1 parameter,
2 given in /sites/www.mysite.de/testconnection.php on line 4



according the file

Code: Select all

   <?php

   if(function_exists('mysqli_connect')){

   if(!($link = mysqli_connect('localhost','user','passwd','my_db'))){

   die('could not connect: ' . mysqli_error($link));

   }

   } else {

   die("don't have mysqli");

   }

   echo 'connect successfully';

   mysqli_close($link);





well i guess that this is saying that 1 parameter was required, 0 were provided. and besides this we surely can say that there absolutly no error checking is being done before calling the function, it's blindly passing a variable that was collected.

interesting: This actually makes sense, given i am probably failing to connect to mysql. 

What we don't see is validation that the credentials work, & i can connect. 

one option would be to ssh to the php server, & then connect over the cli to mysql. Otherwise, we´re just guessing.
Above all - we can say that there probably is no pathing issue. honestly - there are serious doubts that wordpress has a pathing issue, or this is anyway code related.


Code: Select all
active_connections  18446744073709551563
is this number normal? If not how can I reduce it?




If this were the cause of the issue, none of the sites would work,  assuming they are all using the same mysql server. The quickest way to reduce it would be to 
reboot the server. Just posting the number alone doesn't tell us enough. best  thing would be to verify with netstat. If they are active connections, then i probably should have a closer look a the proper firewall rules in place blocking outside connections. 


hmm - i will have a closer look at all the condidions and settings - and will come back and report all the findings. 



have a great day 
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 18. June 2019 22:18

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

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:

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

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


Return Values:

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

Examples:
Example #1 $mysqli->connect_error example

Object oriented style
Code: Select all
<?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

Code: Select all
<?php
$link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');


if (!$link) {
    die('Connect Error: ' . mysqli_connect_error());
}
?>


The above examples will output:


Code: Select all
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


i will run the script and come back and report all the findings.
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby Nobbie » 19. June 2019 09:32

I cant do anything for you, as i dont know webmin and never used it before. It is as it is. Same for wordpress, i dont use wordpress.

Obviously, the call to mysqli_error is invalid for a connect error, as it requires a valid handle to the connection. For connect errors you have to use the special function mysqli_connect_error instead. Not a big thing, or?
Nobbie
 
Posts: 11214
Joined: 09. March 2008 13:04

Re: check the settings of the mysql-db that runs remotely we

Postby Nobbie » 19. June 2019 10:48

unleash_it wrote:agaiin - tbe server is nnot here at home - it is in the hosting center - far from home... away


If you want to connect to that server, you MUST NOT connect to "localhost", instead provide the WAN IP (or a valid domain name) of THAT server. Thats what i already told you above.
Nobbie
 
Posts: 11214
Joined: 09. March 2008 13:04

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 20. June 2019 11:07

hello dear experts of XAMPP and bona sera dear Apachefriends,
good day Nobbie and all the user of Xampp... Wampp and Lampp

some more notes on the topic - how to establish a db connection and what to do when it does not work

well the mysql_connect_error-script is a great help: It returns a string description of the last connect error ( see more infos here: https://www.php.net/manual/en/mysqli.connect-error.php ).  The mysqli_connect_error() function returns the error description from the last connection error, if there is  any error-note. 


but wait - regarding the comparison of mysql and mysql i and PDO - here some ideas

1. The now extinct mysql library and the mysqli library are two completely different animals.
2. so we c an just forget about mysqli and use PDO.

in a picture
+---------+-------------+
| mysql | dodo |
| mysqli | donkey |
| PDO | racehorse |
+---------+-------------+







the return value are the following ones:

a. A string that describes the error.
b. an empty string if no error occurred.

at least this goes for the Version: PHP 5, PHP 7


well - if we run the code below we can get the info bout the option to connect to the db.  What if we run this as a mysql-test-script, and what if we will want to convert it to use mysqli? Can this be done by changing mysql _query($sql); to mysqli _query($sql); ?

Code: Select all
<?PHP

// the test-script that we are running.
$DB["dbName"] = "emails";
$DB["host"] = "localhost";
$DB["user"] = "root";
$DB["pass"] = "";
$link = mysql_connect($DB['host'], $DB['user'], $DB['pass']) or die("<center>Howdy - be aware; There a thing happenede - 
An Internal Error has Occured. Please report following error to the webmaster shot him a mail now.<br><br>".mysql_error()."'</center>");
mysql_select_db($DB['dbName']);
// end header connection part

// function from a functions file that I run a mysql query through in any page.
function executeQuery($sql) {
    $result = mysql_query($sql);
    if (mysql_error()) {
        $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>';
        if ($_SESSION['auto_id'] == 1) {
            $sql_formatted = highlight_string(stripslashes($sql), true);
            $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error();
        }
        die($error);
    }
    return $result;
}

// example query ran on anypage of the site using executeQuery function
$sql='SELECT auto_id FROM friend_reg_user WHERE auto_id=' .$info['auto_id'];
$result_member=executequery($sql);
if($line_member=mysql_fetch_array($result_member)){
    extract($line_member);
} else {
    header("location: index.php");
    exit;
}
?> 




If we do replace mysql_* with mysqli_* then we will have to bear in mind that a whole load of mysqli_* functions need  the database link to be passed.

E.g.: the following ones. 

mysql_query($query)
becomes

mysqli_query($link, $query)
I.e., lots of checking required.

on the other hand side: 

is it suffice if we replace every mysql_* function call with its equivalent mysqli_*, when we will use the procedural API 
 (note: there is some code based on the MySQL API, which is a procedural one - at least afaik), To help with that, the The MySQLi Extension Function Summary-manual is definitely something that will prove helpful. We can do the following: 

we have the following options to do that: 

- mysql_connect will be replaced by mysqli_connect
- mysql_error will be replaced by mysqli_error and/or mysqli_connect_error, depending on the context
- mysql_query will be replaced by mysqli_query ,,,, and so on and so forth. 



Note: For some functions, we may need to check the parameters very very carefully: Maybe there are 
some differences here and there -- but not that many differences. Belive me. Both mysql and mysqli-codes are based on the same library ( the great and powerful libmysql ; at least for PHP-version <= 5.2)

Usage - for instance:
with mysql, we have to use the mysql_select_db once connected, to indicate on which database we want to do our queries mysqli, on the other side, allows us to specify that database name as the fourth parameter to mysqli_connect.


well Wahat do you think bout this...
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 20. June 2019 11:31

hi there - hello again Nobbie
hello daer Apachefriends,

some words regarding the installation: I have Linux Server. Apache 2.4.10, PHP Version 5.6.39 and mysqlnd 5.0.11-dev - 20120503 -
installed. There are several wordpress website running on server. I have checked this all one week ago, In the phpinfo();

what do you suggest - should i ask my serveradmin that he will update & upgrade the whole system - in order to have a modern system... And then i run the mysqli_error_(function)

LOVE TO HEAR FROM YOU
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 20. June 2019 20:47

hello again - i am back again.

well at the moment i am trying to make sure that i have set up the MySQL use to be able to access the database via localhost? - this is pretty important for me - i need to have more insights!
Aferward i have to try using the following code to connect to the DB

Code: Select all
<?php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

/*
 * This is the "official" OO way to do it,
 * BUT wait - the $connect_error was broken until PHP 5.2.9 and 5.3.0. - so i have to make sure if i am the one that must be careful here
 */
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}

$mysqli->close();



well Nobbie i have to do some more test. 


dear Nobbie, i keep you posted - and i come back and report all the findings. 
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 22. June 2019 11:26

hello dear nobbie hello dear all

posted this .
Code: Select all
<?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();



got back this  result ... 


Code: Select all
Parse error: syntax error, unexpected end of file in /sites/www.mysite.de/new_test.php on line 13


well i try to figure outwhat goes wrong here
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

Re: check the settings of the mysql-db that runs remotely we

Postby unleash_it » 22. June 2019 13:56

hello dear all - good day dear Nobbie,

and besides the php-configuration 


if i use code with a closing tag -  like so... .



Code: Select all



<?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 



Code: Select all

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





still wonder what is going on here . and what i can do and test now
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1

command prompt from within a Python how to apply !?

Postby unleash_it » 06. October 2019 20:51

hello dear Nobbie, good day dear experts on ApacheFriends,


imagine i am on Windows and type at the command prompt from within a Python script?

can i do this with

- the subprocess module in the standard library:

Code: Select all
import subprocess
subprocess.run(["ls", "-l"])



The official Python-documentation recommends the subprocess module over the alternative os.system():

my question is: which method id more powerful has more advantages - what are the downsides?

a big big advantage from os.system: it passes the command and arguments to our system's shell.

Code: Select all
 os.system("some_command with args"):


This is very cool - because we can perform multiple commands at the same time; in this manner and set up pipes and input/output redirection.

The advantage of subprocess vs. system is told to be
- more flexible : since we can get the stdout, stderr, the "real" status code, .
- the subprocess module provides more powerful facilities for spawning new processes and retrieving their results;
- and lots of other things more...

os.system("some_command with args") passes the command and arguments to our system's shell.
a very very cool features: we are able to perform multiple commands at the same time.
and we can set up pipes and input/output redirection.

Code: Select all
os.system("some_command < input_file | another_command > output_file") 



which approach do you use - how do you call an external command in Python?
unleash_it
 
Posts: 49
Joined: 10. December 2011 18:32
Operating System: linux opensuse 12.1


Return to Webmin

Who is online

Users browsing this forum: No registered users and 0 guests