does cacti works with php5-mysqlnd ?

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Moderators, Developers

Author
Message
c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

does cacti works with php5-mysqlnd ?

#1 Post by c3226026 » Sat Feb 18, 2012 1:01 pm

Hello all,

I'm on debian and I try to test cacti with php5-mysqlnd, but it seems than some variables should not be the same.

I'm explained, if I test with php5-mysql all work fine, I can access normaly to cacti. If I replace php5-mysql by php5-mysqlnd I've this error :

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

like as include/config.php is no ok, but between the change (php5-mysql to php5-mysqlnd) I've done no change on this file, and if I replace php5-mysqlnd by php5-mysql all work fine again.

In the same time I think than connection between php5 and mysql server is ok when I used php5-mysqlnd, because I can access normally to cacti database by phpmyadmin.

I've no error on apache and mysql log files.

So my question, what specifical value does I used on include/config.php file) because like this :

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;

doesn't seems good, so if any people use php5-mysqlnd or know what I need to change, please tell me.

Thanks in advanced

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#2 Post by noname » Sun Feb 19, 2012 9:26 pm


c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#3 Post by c3226026 » Mon Feb 20, 2012 4:29 am

Hello noname,

Thank's for your return, I've already see it, but as I'm on 5.5 version and not 4.1. I haven't try it.
I will try and give you my return.

[Edit] but I don't used old authentication [/Edit]

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#4 Post by c3226026 » Mon Feb 20, 2012 12:49 pm

Hello noname,

I've try but that not match (I used php5.3.10 and mysql 5.5-20 in the two cases) and I don't use old-passwords=1 so password are good :

+-------------------------------------------+
| PASSWORD('test') |
+-------------------------------------------+
| *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 |
+-------------------------------------------+

and

+-------------------------------------------+
| PASSWORD('cactiuser') |
+-------------------------------------------+
| *E78847AB327B6E8EEF81CE30F4C4A88D903AEF29 |
+-------------------------------------------+


I want used php5-mysqlnd because it's recommanded with mysql 5.5

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#5 Post by noname » Mon Feb 20, 2012 8:15 pm

Then try:

Code: Select all

$database_hostname = "127.0.0.1";
- https://bugs.php.net/bug.php?id=45150 (Not a bug)
...
mysqlnd uses the PHP streams, compared to libmysql, which does the network i/o itself. Thus, if mysqlnd can't resolve localhost to 127.0.0.1, then PHP should not be able too. Could you try to reproduce that. mysqlnd does nothing special, just uses IPv4 to open a TCP connection.

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#6 Post by c3226026 » Tue Feb 21, 2012 1:16 am

Hello noname,

Many thanks for your help.

I've try with $database_hostname = "127.0.0.1"; but no change.

Server use only IPV4, IPV6 is disable by grub so no IPV6 result

I've done the different tests :

<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($link) . "\n";

mysqli_close($link);
?>


no result on the two cacse (php5-mysql and php5-mysqlnd) => blank page
But I don't think than this test is ok, because if I replace root by toto same result


other test :

<?php

$httpfile = file_get_contents("http://127.0.0.1/cacti/foo.txt");

print "File contents read using 127.0.0.1: \n\n" . $httpfile . "\n\n";

$httpfile = file_get_contents("http://localhost/cacti/foo.txt");

print "File contents read using localhost: \n\n" . $httpfile . "\n\n";

?>
result
File contents read using 127.0.0.1: t works File contents read using localhost: t works



But if I use phpmyadmin, mysql server connection is ok in the two cases (php5-mysql and php5-mysqlnd), that means than connection beetwen php5 and mysql is ok no ?

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#7 Post by c3226026 » Tue Feb 21, 2012 6:22 am

Hello nomane,

I've done new tests with this file :

<?php
mysql_connect("localhost", "cactiuser", "my_password") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("cacti") or die(mysql_error());
echo "Connected to Database";
?>

result :
Connected to MySQL
Connected to Database

So connection between php5 and mysql server (with php5-mysqlnd) seems OK, becauce if I put wrong value (for user or database), script tell me it like this :

with wrong user :
Access denied for user 'titi'@'localhost' (using password: YES)

and with good user but wrong database :
Connected to MySQL
Access denied for user 'cactiuser'@'localhost' to database 'titi'

so I think than may be syntax is different on config.php with php5-mysqlnd

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#8 Post by noname » Tue Feb 21, 2012 6:51 am

c3226026 wrote:so I think than may be syntax is different on config.php with php5-mysqlnd
Hmm, interesting...
But sorry, I can't verify these differences because I don't have the latest PHP/MySQL environment that native driver (mysqlnd) included.

BTW, just curious, does this code work in your mysqlnd environment?
That tries to connect database using ADONewConnection() like as Cacti does. If it failed, perhaps Cacti fails too.

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#9 Post by c3226026 » Tue Feb 21, 2012 11:56 am

Hello noname,

I've try this :

<?php
$conn = &ADONewConnection('mysql');
$conn->PConnect('localhost','cactiuser','my_password','cacti');
$sql = 'select hostname,description from host;';
$recordSet = &$conn->Execute($sql);
if (!$recordSet)
print $conn->ErrorMsg();
else
while (!$recordSet->EOF) {
print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
$recordSet->MoveNext();
}
$recordSet->Close();
$conn->Close();
?>

Result :
127.0.0.1 Localhost


So for me it confirms than connection between php5 with php5-mysqlnd and mysql server is OK, so I think it's a cacti "code" issue, and I think this last test is a good advanced, do you agree with it ? The difficulty will be finding the good code to use :wink:

If you've any other idea, I can test it

may be solved in cacti 1.0.0 :roll:

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#10 Post by noname » Wed Feb 22, 2012 4:02 am

Okay, then, does this code work with mysqlnd?
It seems relevant code for DB connection has changed since 087h. (Please see db_connect_real() in 'lib/database.php')

Code: Select all

<?php
include("./include/global.php");
include_once($config["library_path"]."/database.php");

$dsn = 'mysql://cactiuser:[email protected]/cacti?persist&port=3306';
$conn = ADONewConnection($dsn);

$sql = 'select hostname,description from host;';
$recordSet = &$conn->Execute($sql);
if (!$recordSet)
        print $conn->ErrorMsg();
else
        while (!$recordSet->EOF) {
                print $recordSet->fields[0].' '.$recordSet->fields[1].'<BR>';
                $recordSet->MoveNext();
        }
$recordSet->Close();
$conn->Close();
?>

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#11 Post by c3226026 » Wed Feb 22, 2012 5:05 am

many thanks for your help, I've try your code but not database connection :

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

if than can help, if I comment this two lines :

include("./include/global.php");
include_once($config["library_path"]."/database.php");

in the two cases, I've blank page, many sorry to not give you more help, but I'm not dba.

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#12 Post by noname » Wed Feb 22, 2012 5:21 am

c3226026 wrote:I've try your code but not database connection :

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'
Is that very error you mentioned at your original post in this topic?

>> in the two cases, I've blank page

If possible, please perform that code again from CLI (not via browser) and see PHP error log.
Probably root cause of this issue is there..

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#13 Post by c3226026 » Wed Feb 22, 2012 5:37 am

Yes it's same error than the original topic.

I've try by cli, but I've same error and no error in php log, because I've no php log file.

[update1] In fact php log is on but in syslog file, but not error for this code, I check more [/update1]

c3226026
Cacti User
Posts: 87
Joined: Mon Jan 17, 2011 12:15 pm

Re: does cacti works with php5-mysqlnd ?

#14 Post by c3226026 » Thu Feb 23, 2012 3:18 pm

In fact php repport only :

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: does cacti works with php5-mysqlnd ?

#15 Post by noname » Thu Feb 23, 2012 7:40 pm

c3226026 wrote:In fact php repport only :

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'
Probably that error is not recorded by the above test code. Then there is no clue..

Post Reply