I am connecting to a MySQL database using a PHP script. When the script runs from my hosting it works fine, connection successful. However when I run it from my local XAMP server to test it, it does not work. So I looked at the error and it says:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'somedomain.net' (using password: YES)
Script is as follows:
<?php
$host = "somehost.com";
$username = "username";
$passwd = "password";
$dbname = "db";
$port ="xxxx";
// Create connection
$con = mysqli_connect($host, $username, $password);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Somehow it is adding the DNS name from my local machine to the username. How do I ignore this?
Now that I added the host, I am getting this error:
Connection failed: Access denied for user 'username'@'somedomain.net' (using password: NO)
CodePudding user response:
I guess this is why you can not connect
Maybe one of these problems is you have:
- you are not connected from somedomain.net
- your password does not correct
- your username does not access the database
The best solution in my mind is to add a new user for connecting to your database from your local machine.
CodePudding user response:
This worked. The parameter 'passwd' was a typo and after I added the host name on remote host list it all worked fine thanks!