Hello everyone am trying to connect to MySQL database but getting this error:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'#'localhost' (using password: YES) Error: Could not establish connection.Access denied for user 'root'#'localhost' (using password: YES).
Here is my code:
<?php
$host = "localhost";
$db = "resumedb";
$username = "root";
$password = "sa";
$phpConnect = mysqli_connect($host, $username, $db, $password);
//checking the if connection.
if($phpConnect === false)
{
die("Error: Could not establish connection.".mysqli_connect_error());
}
?>
The right syntax is:mysqli_connect("myhost","myuser","mypassw","mybd")
so try:
$phpConnect = mysqli_connect($host, $username, $password, $db);
refer this
Basically If you are the newbee in PHP so you should
1.first start the Xamp/Wamp service.
2.else db credentials for password should be $password = "".
Related
Used code for connection
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword);
?>
current settings:
^User name, Host name, Password, Global privileges, User group, Grant^
Error:
Warning: mysqli_connect(): (HY000/1045): ProxySQL Error: Access denied for user 'root'#'2a02:4780:bad:f00d::16' (using password: NO) in /storage/ssd3/007/15887007/public_html/dbh.php on line 5
I'm using 000webhostapp.com for my website and XAMPP for database
You didn't add database name.
$dbname = 'your db';
I'm trying to connect my PHP to my XAMPP DB server, but as it seems I'm not doing something right.
This is my code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$db= "blogdata";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
And it returns:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'username'#'localhost' (using password: YES) in C:\xampp\htdocs\KungFu\Blog.php on line 8
Connection failed: Access denied for user 'username'#'localhost' (using password: YES)
I think everything is correct, tried different variations but as you can tell it is not working.
Best way to connect php to MySQL is to use new method : PDO :)
PHP :
$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
I tried using the following code in php:
<?php
$servername = "www.psgcirdask.com";
$username = "xxx"; //hidden for security purpose
$password = "password";
$dbname = "psgcilqh_calibration";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM brands";
$result = $conn->query($sql);
$conn->close();
?>
I got an error:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'xxx'#'157.51.147.43' (using password: YES) in C:\xampp\htdocs\justshawarmapos\checkthedatabase.php on line 9
Connection failed: Access denied for user 'xxx'#'157.51.147.43' (using password: YES)
But i use the same username and password to connect to my database in my website.I am getting this problem only when i connect using local server.
You have to enable remote access in your mysql database.
Check this link
For hostgator
Check if all the infos provided are correct especially the servername then try to figure out if you have the right permission to access that database with that user!
I am trying to access a PHP database I created online using this URL
http://dns.com/data_api/connect.php
I have created the database and it has no username and password attached to it at the point of creation. When I try to check if the connect.php could establish a connection to the database I get this error
Warning: mysqli_connect(): (28000/1045): Access denied for user 'mobileto'#'localhost' (using password: NO) in /home/mobileto/public_html/data_api/connect.php on line 11
Failed to connect to MySQL: Access denied for user 'mobileto'#'localhost' (using password: NO)
This is the connect.php file
<?php
$username = "";
$password = "";
$hostname = "localhost";
$dbase ="mobileto_holo";
//connection to the database
//$dbhandle = mysql_connect($hostname, $username, $password)
$con=mysqli_connect($hostname,$username,$password,$dbase);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// or die("Unable to connect to MySQL");
//echo "Connected to MySQL<br>";
//$conn = mysql_connect("localhost","root","");
?>
Please what could be wrong?
No Username or Password? :o That's impossible. Try giving root as the default username, instead of passing an empty string.
$username = "root";
$password = "";
$hostname = "localhost";
$dbase = "mobileto_holo";
I am trying to connect to MySQL on the server but gives following error. User is created and granted all privileges.
It's working on local machine but not after deploying to a server.
Also mysql_connect function works but new mysqli() gives access denied as mentioned below.
Also Tried adding port.
Warning: mysqli::mysqli(): (HY000/1045): Access denied for user ''usernam'#'localhost' (using password: YES) in /home/domainname/public_html/autopublish/test.php on line 8
Connection failed: Access denied for user ''username'#'localhost' (using password: YES)
<?php
$servername = "localhost";
$username = "'xxxxx";
$password = "xxxxx";
$dbname = "xxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password); **//line 8**
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "no connection";
}
$sql = "SELECT * FROM pages";
$result = $conn->query($sql);
$data = array();
$arr = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
}
} else {
echo "No Token";
}
print_r(json_encode($data));
$conn->close();
?>
Either the user does not have the required rights for the database or the password is wrong.
Otherwise remove the user and use the following statement to create:
1.CREATE USER 'user'#'localhost' IDENTIFIED BY '123456789';
2.
3.GRANT ALL PRIVILEGES ON project.* TO 'user'#'localhost' WITH GRANT OPTION;
or try this:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
//Create
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new mysqli($servername, $username, $password, $dbname);
echo "Yaaay";