i uploaded my site to hostinger but i encountered the following problems - php

Warning: mysql_connect(): Access denied for user 'root'#'10.2.1.12'
(using password: NO) in
/home/u749031689/public_html/Enrollment/includes/dbcon.php on line 8
Access denied for user 'root'#'10.2.1.12' (using password: NO)Not
<?php
$Server="localhost";
$unameDB ="root";
$passDB ="";
$dbName="u749031689_enrol";
$sqlCon = mysql_connect($Server, $unameDB, $passDB) or die (mysql_error(). "Not connected");
mysql_select_db($dbName, $sqlCon);
?>

You have to create your database to the hostinger server and then you need to replace your '$Server', '$unameDB', '$passDB' and '$dbName' values as per your hostinger database details.
Your code would be as follows.
<?php
$Server="YOUR HOSTINGERS DATABASE SERVER NAME";
$unameDB ="YOUR HOSTINGERS DATABASE USER NAME";
$passDB ="YOUR HOSTINGERS DATABASE PASSWORD";
$dbName="u749031689_enrol";
$sqlCon = mysql_connect($Server, $unameDB, $passDB) or die (mysql_error(). "Not connected");
mysql_select_db($sqlCon, $dbName);
?>

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

Which username/password do I use to connect to mySQL

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

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

php establishing connection with mysql database

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 = "".

Categories