Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird error on connection with database

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
like image 408
KostasC Avatar asked May 27 '26 19:05

KostasC


1 Answers

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.

like image 199
KostasC Avatar answered May 30 '26 09:05

KostasC