I have a custom application written on php, which is connecting with database. If I run it on the windows wamp server the application is connect correct with the database. If I run it on the ubuntu apache2 i am getting the following error:
<b>Warning</b>: mysqli::real_connect(): (28000/1045): Access denied for user 'user'@'localhost'
(using password: YES) in <b>/var/www/html/reportCMS/php/classes/Database.class.php</b> on line <b>137
</b><br />
<br />
<b>Warning</b>: mysqli::set_charset(): invalid object or resource mysqli
in <b>/var/www/html/reportCMS/php/classes/Database.class.php</b> on line <b>141</b><br />
<br />
<b>Warning</b>: mysqli::prepare(): invalid object or resource mysqli
in <b>/var/www/html/reportCMS/php/classes/Database.class.php</b> on line <b>829</b><br />
<br />
<b>Fatal error</b>: Problem preparing query (SELECT id,username,password,type from user WHERE BINARY
username=? AND active=1 ) Access denied for user 'user'@'localhost' (using password: YES) in <b
>/var/www/html/reportCMS/php/classes/Database.class.php</b> on line <b>830</b><br />
And the Database.class.php line 137 is:
$this->_mysqli = mysqli_init();
$this->_mysqli->real_connect( $this->host, $this->username, $this->password, $this->db, $this->port );
$this->_mysqli->set_charset ('utf8');
The connection with database in both cases, is on the ubuntu machine with mysql.
Can you guide me, how to find the error? If you need more information please tell me.
EDIT: The only difference is on the config file for the permissions, which on the ubuntu is localhost. And on the windows machine is the IP of the ubuntu. But I have grant the permission both for localhost and % on the mysql.
EDIT2:(for the @ anant kumar singh suggestion)
Warning: mysqli::real_connect(): (HY000/1045): Access denied for user 'user'@'myip' (using password: NO) in C:\wamp\www\reportCMS\php\classes\Database .class.php on line 138
Warning: mysqli::set_charset(): invalid object or resource mysqli in C:\wamp\www\reportCMS\php\classes\Database.class.php on line 142
Warning: mysqli::prepare(): invalid object or resource mysqli in C:\wamp\www\reportCMS\php\classes\Database.class.php on line 830
Fatal error: Problem preparing query (SELECT id,username,password ,type from user WHERE BINARY username=? AND active=1 ) Access denied for user 'user'@'myip (using password: NO) in C:\wamp\www\reportCMS\php\classes\Database.class.php on line 831
Finally I solved it. My mistake was that the config file(username, password, db) is created on Windows. Because of that there some whitespaces insert on the file, I remove it from the Ubuntu with the Netbeans and it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With