000webhost mysql connection error - php

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.

Related

Connecting PHP with MySQL DB in XAMPP issues

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', '');

Connect online mysql database with the local xampp server using php

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!

Warning: mysqli_connect(): (28000/1045): Access denied for user 'mobileto'#'localhost' (using password: NO)

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";

Can't connect to database with 000webhost

I'm trying to learn php but when I attempt to connect to a mysql database, I get this error. I don't think anything is wrong with the code itself but perhaps there is an error on the hosts side? I'm using 000webhost so.
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied
for user 'a7976620_db1user'#'localhost' (using password: YES) in
/home/a7976620/public_html/index.php on line 17
Here is my php:
<?php
$servername = "localhost";
$username = "a7976620_db1user";
$password = "******";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
In https://www.000webhost.com, there are two options in the cPanel:
Fix ownership and
Fix file permissions
You can apply this and it will be fine.

grant access to new user phpmyadmin locally

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"; }
?>

Categories