我在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。但是我已经为myshost上的localhost和%授予了权限。
EDIT2:(适用于@ anant kumar singh建议)
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
答案 0 :(得分:0)
最后我解决了。我的错误是在Windows上创建了配置文件(用户名,密码,db)。因为在文件上插入了一些空格,我将它与Netbeans一起从Ubuntu中删除它并且它有效。