Im working locally with XAMPP, and I'm attempting to connect to the database with a new user.
The username has all permissions granted both globally and specific to that table (altough theres no need for both), but when I try and connect using the code below I get an error, I have no issues connecting with 'root'.
I've double checked passwords.
Am I missing something else?
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'myshop'#'localhost' (using password: YES) in C:\xampp\htdocs\myshop\db_connect.php on line 8
Couldnt Connect to DB
<?php
$db_name = 'myshop';
$username = 'myshop';
$password = 'myshop';
$host_name = 'localhost';
$connect = mysqli_connect($host_name,$username,$password,$db_name);
if ($connect) { echo "<br />Success"; } else { echo "<br />Couldnt connect to DB"; }
?>
Related
So, I'm SUPER new to mySQL. Having issues connecting to my database with PHP. Hoping someone can point me in the right direction.
I can login to our Cpanel using my username/password. Using the web gui I was able to create a database.
Now when I try to connect to the database (or even just the server for that matter) using PHP I get an error:
Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'username'#'servername' (using password: YES) in /home/ropepart/public_html/techportal/sandbox/mysqltest.php on line 8
Connection failed: Access denied for user 'username'#'servername' (using password: YES)
To me, it seems like this is a username/password error. But I an using the same username/password that I use to login to the web gui. Why can I successfully login there, but can't login with PHP?
Here's my code (taken pretty much directly from W3Schools):
<?php
$servername = "servername";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
(Hopefully it's obvious that I've changed my servername/username/password for the purposes of this post)
Check the details correctly, By deafult
host = localhost
username = root
password = (No password leave it as empty)
database = (your database)
<?php
$connection = new mysqli('host','username','password','your_database');
if($connection->connect_error || $connection->error){
echo "error";
}else{
echo "done";
}
?>
you should add database name.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo"
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
//if you are using xampp you shoul locate this file you get information from this
passwords.txt
MySQL database username/password is not necessarily same as cPanel username & password.
Here is what you should do:
Login to your cPanel
From dashboard click "MySQL® Databases"
Add a new user from there (https://prnt.sc/kpiby9). Just fill username
and password (note down the password).
Add that user with your database by selecting both from the dropdown
(https://prnt.sc/kpidqx)
Now, use this username & password to connect with the database.
mysqli_connect(serverhostname,username,password,dbname);
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!
Hey guys I'm new to MySQL and am having a little trouble with getting it to load. I have it all set up and running in my localhost page but as soon as I upload the folder to my server it says connection failed using password"yes". Idk why this is happening and have spent the past couple of hours trying to solve it but google has not been much help.
I created a database and used php to access that db. I have tried switching local host to a domain, to an ip address, and everything else i could think of but nothing has worked. It only works in the development localhost page.
Any advice is greatly appreciated.
edit-
This is the code
<?php
$servername = "localhost";
$username = "rudy_dps";
$password = "******";
$dbname = "******";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, qual, name FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Qualifications</th><th>Name</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["qual"]."</td><td> ".$row["name"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
and this is the error i get
Connection failed: Access denied for user 'rudy_dps'#'localhost' (using password: YES)
What exactly the message say? My initial thought on the error is that it would say:
Connection failed: Access denied for user 'XXXX'#'XXXX'
(using password: YES)
Which can mean only one of two things:
Your password is incorrect, or
Your user doesn't have privileges to connect to that database.
There is a mismatch in the configuration of your mysql.
Execute the following command in your database
GRANT ALL PRIVILEGES ON . TO BY 'USER'#'%' IDENTIFIED BY 'PASSWORD'
then
FLUSH PRIVILEGES
I am trying to connect to my database using the following code:
<?php
$mysql_host = "mysql*.000webhost.com";
$mysql_database = "a******_account";
$mysql_user = "a******_admin";
$mysql_password = "******";
// Create connection
$con=mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
};
?>
Does anyone know what is going on?
The error messages are:
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'a******_admin'#'0.0.0.0' (using password: YES) in /home/a3996154/public_html/index.php on line 18
and
Failed to connect to MySQL: Access denied for user 'a******_admin'#'0.0.0.0' (using password: YES)
Probably: Your auth is wrong, or that user doesn't have permission to access to that database.
Sorry, it took a day for the database to respond, today it is up and running. Excuse me for any time I wasted.
im trying to code a simple login in php+mysql. Everytime i hit submit button i get this error
Could not connect to MySQL: Access denied for user 'root'#'localhost' (using password: YES)
This is code that im using to connect to mysql:
<?php
// Create a connection to the logindb database and to MySQL.
// Set the encoding and the access details as constants:
DEFINE ('DB_USER', 'johny');
DEFINE ('DB_PASSWORD', 'some_pass');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'biblioteczka');
// Make the connection:
$dbcon = #mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME)
OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$ID = $_POST['user'];
$PASSWORD = $_POST['pass'];
// Set the encoding...
mysqli_set_charset($dbcon, 'utf8');
function SignIn(){
session_start();
if(!empty($_POST['user'])){
$query = mysql_query("SELECT * FROM userName where user ='$_POST[user]' and pass = '$_POST[pass]'"
or die(mysql_error));
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']) AND !empty($row['pass'])){
$_SESSION['userName'] = $row['pass'];
echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";
} else {
echo "SORRY... YOU ENTERD WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
}
if(isset($_POST['submit']))
{
SignIn();
}
?>
I have 2 accounts root and johny, they have all priviliges and i set the passwords and i can work on database that i created.
phpmyadmin config:
I don't know where's the problem at this points that's why im asking for help.
Sorry for my english i'm not a native speaker
You connected to the database using the mysqli_ library.
Then you tried to query it with the (obsolete) mysql_ library.
The latter doesn't have a connection to the database, so it tried to open one (and failed).
Pick one library and use it consistently.