2
我有一个自定义应用程序写在php上,它正在与数据库连接。如果我在windows wamp服务器上运行它,应用程序与数据库连接正确。如果我在Ubuntu的Apache2运行它我收到以下错误:与数据库连接出现奇怪的错误
<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 />
而且Database.class.php行137:
$this->_mysqli = mysqli_init();
$this->_mysqli->real_connect($this->host, $this->username, $this->password, $this->db, $this->port);
$this->_mysqli->set_charset ('utf8');
在这两种情况下,与数据库的连接,是与MySQL的Ubuntu机器。
你能指导我吗,如何找到错误?如果您需要更多信息,请告诉我。
编辑: 唯一的区别是配置文件的权限,在ubuntu上是localhost。而在Windows机器上是Ubuntu的IP。但是我已经授予localhost和mysql上的权限。
EDIT2:(为@安嫩特·库马尔·辛格建议)
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
你正在使用一些密码。尝试给予''''。 –
@anantkumarsingh你能更具体吗? – KostasC
您确定您提供的用户名和密码是否正确并能够从终端连接到数据库? – Raja