Weird error on connection with database - php

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.

Related

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\wamp64\www\web\db.php on line 3

( ! ) Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) in C:\wamp64\www\web\db.php on line 3
Call Stack
# Time Memory Function Location
1 0.0840 407896 {main}( ) ...\registration.php:0
2 0.0850 408192 require( 'C:\wamp64\www\web\db.php' ) ...\registration.php:73
3 0.0850 408192 mysqli_connect ( ) ...\db.php:3
Failed to connect to MySQL: Access denied for user 'root'#'localhost' (using password: YES)
Everything look ok, but still getting problem in connection with phpmyadmin.
It seems like you're using WAMP. WAMP's default user is root and the password is blank (unless you had changed it). You're connecting to MySQL with a password (see using password: YES), it needs to be using password: NO; meaning logging in with a blank ('') password. In \db.php:3 rewrite the MySQL password for mysqli_connect with '' and try again.

php can not connect to mysql after reboot server

Software:
PHP 7.3
MySQL Workbench 8.0
This is my PHP code:
try {
$link = mysqli_connect($DB_SERVER,$DB_USERNAME, $DB_PASSWORD,$DB_NAME,3306);
} catch (Exception $e){
throw new Exception("Can't execute command. ERROR: ".$e);
}
This is the error:
Warning: mysqli_connect(): PHP was built without openssl extension, can't send password encrypted in login.php on line 11
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'XXXXX_admin'#'localhost' (using password: YES) in C:\inetpub\wwwroot\ on line 11
PHP Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\inetpub\wwwroot\ on line 24
PHP Fatal error: Uncaught Exception: ERROR: Failed to connect to in C:\inetpub\wwwroot:24 Stack trace: #0 {main} thrown in C:\inetpub\wwwroot\ on line 24
Now the magic, when I login in to mysql workbench with the same user and password everything works fine. I have access to tables and other things. When I login in with my PHP application everything works also.
So my problem is everytime my server reboots I have to login in with MySQL Workbench, to get it working again. What am I missing?
You need to do verify few of the steps:
All necessary extensions are enabled like mysqli, openssl etc
Port is available
MySQLi is connecting at 3306 Port
Rest could be your username and password issue
Let us know once you will be verifying all above steps.
What you need to do is enable the openssl extension for php.
Open your php.ini file and search for the line:
;extension=php_openssl.dll
You need to uncomment it by removing the semicolon in front of it, leaving you with this:
extension=php_openssl.dll

opencart installation issue on step 3 windows

i cannot install opencart on third step.i have the following problem:
Warning: mysqli::mysqli(): (HY000/1045): Access denied for user
'root'#'localhost' (using password: NO) in
C:\wamp\www\opencart\upload\system\library\db\mysqli.php on line
7Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
C:\wamp\www\opencart\upload\system\library\db\mysqli.php on line
10Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
C:\wamp\www\opencart\upload\system\library\db\mysqli.php on line
10Notice: Undefined variable: mysql in
C:\wamp\www\opencart\upload\install\controller\install\step_3.php on
line 280Notice: Trying to get property of non-object in
C:\wamp\www\opencart\upload\install\controller\install\step_3.php on
line 280
php× 1144494
If someone is getting same type of error ,you could try out this,
username=admin
password=
keep your password null
The reason this might happened is because of password you gave in phpmyadmin during setting time.

Synology MSQL connection error

I tried to move a database from XAMPP to my Synology NAS.
Now I get this error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'qs'#'localhost' (using password: YES) in /volume1/web/db.php on line 3
In the Database i created a User:
Name: qs
password: test
host: %
privileges: all..
in php i use:
$link=mysqli_connect("localhost","qs","test","qs",3306);
localhost because the Synology is the localhost of the web-page. i also tried to change to:
$link=mysqli_connect("10.0.0.99","qs","test","qs",3306);
then it says:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'qs'#'JF_SYN' (using password: YES) in /volume1/web/db.php on line 3
"JF_SYN" is the name of my Synology
i also tried to set the host of the database user, to that specific IP, but that doesn't change anything.
Database connection is working with this user and the password, i tried with HeidSQL,MSYQL-Workbench and Oracle SQL Developer, all those tools can make a connection.
I had the same issue, with my Synology NAS
Use MyAdmin and remove the “ANY” or “Anonymous” user accounts.
This should Fix your issue.

Problem Connecting to MySQL Database on Production Server

I put my files on my server, but I'm unable to connect to the database. My project works on my local machine, but not on my production server.
I'm using mysql and php.
I'm getting this error:
[01-Nov-2010 18:27:01] PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'dbuser'#'localhost' (using password: YES) in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 20
[01-Nov-2010 18:27:01] PHP Warning: mysql_select_db() [<a href='function.mysql-select-db'>function.mysql-select-db</a>]: Access denied for user 'mysite'#'localhost' (using password: NO) in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 21
[01-Nov-2010 18:27:01] PHP Warning: mysql_select_db() [<a href='function.mysql-select-db'>function.mysql-select-db</a>]: A link to the server could not be established in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 21
[01-Nov-2010 18:27:01] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Access denied for user 'mysite'#'localhost' (using password: NO) in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 28
[01-Nov-2010 18:27:01] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 28
[01-Nov-2010 18:27:01] PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 31
[01-Nov-2010 18:27:01] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote_quiz/MyData.php on line 46
Does this error mean that my password is incorrect? Any suggestions?
Thank you.
-Laxmidi
Either your user or password is wrong (or even your server, but that's more rare).
Be aware that there are two users on that stacktrace, 'dbuser' and 'mysite', could be related to that?
Thank you for the help. I made a dumb error. My host prefaces the user name and the database name with the site's user name in order to avoid conflicts. I forgot about that.

Categories