Access denied for user 'consult'#'localhost' (using password: NO) - php

I am using bluehost domain. I want to connect database but I don't know password. After the long war I found the username and localhost name. I am a beginner. Help me to find the phpmyadmin password.
This my php database conection code.This code is worked in localhost.
$link = mysql_connect('localhost', 'consult', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('consultv_hrms', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}

Only the admin can reset database password. In this case you need to follow the instructions given by your hosting provider
Log into the cPanel
Click the MySQL Databases icon under the "Databases" category
Change the password
Refer this for detailed instructions

Related

error: Access denied for user 'root'#'localhost' (using password: NO)

I'm trying to implement a login function that allows me to extract data from facebook and save them on my moodle Website. Unfortunately, I'm not a programmer and I'm having some problems. In particular, I'm having some difficulties -I believe- related to the permission rights when I try to "write" the data extracted from fb on a MySQL database.
This is what I have done so far:
I managed to extract from Fb the data that interest me and I tried to save them to a MySQL database (created through cpannel). The code I used to access the database is basically this (with the correct parameters for my database):
// Create connection
$ Db = new mysqli ($ localhost, $ username, $ password, $ database);
// Check connection
if ($ db> connect_error) {
die ( "Connection failed:". $ db-> connect_error);
}
But when I connect to the web page I get this error: "Connection failed: Access denied for user 'root' # 'localhost' (using password: NO)"
The problem seems to be that the user/pass are incorrect. In fact, I am sure the data correspond to those included in CPannel by me at the time of database creation. The associated user has all active privileges.
I did some research and it it seemed that the problem could be associated with some "automatic" setting of Moodle. So I uninstalled moodle but nothing has changed.
I also tried to change the code:
$config = parse_ini_file('/config.ini');
// Connect to database
$mysqli = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);
printf("\n ".date("Y-m-d h:i:sa") . " - Establishing connection to " . $config['dbname'] . " on " . $config['servername'] . ".\n");
// Check connection
if ($mysqli->connect_error) {
die('Error : (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
printf("\n ".date("Y-m-d h:i:sa") . " - Connection failed. Returned error: " . mysqli_connect_error() . "\n");
} else {
printf("\n ".date("Y-m-d h:i:sa") . " - Connection successful.\n");
}
Unfortunately I had no luck ...
This is the tutorial i followed to implement the function:
https://www.youtube.com/watch?v=N5Kka43giyY&index=30&list=PLmpuiTmSb3xCLwwkpXeuJxwKyljf7e3Tx
I am very inexperienced, but it seems to me that the problem arises when I define password in cpannel ... it is as if the password had no value ..
Any ideas on how I can resolve it?
The problem should be related to the host parameter of the connection, review your CPanel data and try to find the host, like an IP address or domain provided by your CPanel.
You can replace $config['password'] with real password like 'your-password' in your below mysql query
$mysqli = new mysqli($config['servername'], $config['username'], 'your-password', $config['dbname']);

PHP - Cannot connect to MySQL database

I am trying to connect to my MySQL database through php, I am managing my Database with phpmyadmin. To login the username is root and I dont have a password. My problem is I cant connect, I get the "Could not connect to mySQL database" message when I try to
Below is my Code
<?php
session_start();
$server = 'localhost';
$db_usernmae = 'root';
$db_password = '';
$database = 'househockey';
if(mysql_connect($server, $db_usernmae, $db_password)){
die('Could not connect to mySQL database');
}
if (mysql_select_db($database)) {
# code...
die('couldnt connect to database');
}
?>
Im not sure if it matters, but I am using WAMP and I put my phpmyadmin folder into my htdocs folder.
Thanks
As you have written your code :
if(mysql_connect($server, $db_usernmae, $db_password)){
die('Could not connect to mySQL database');
}
This will when connection is true print the following: die('Could not connect to mySQL database'); I think what you need to test your connection, which sounds like it should work:
if(!mysql_connect($server, $db_usernmae, $db_password)){
die('Could not connect to mySQL database');
}
The ! will negate the returned value of your mysql_connect and tell you if you're connected.
As far as I know, PMA explicitly needs a username and password. Set a root password through
mysqladmin -u root password NEWPASSWORD and then change your PMA config, followed by a server restart. Alternatively, use MySQL workbench. It does more than create entity relationship diagrams (ERDs).
You may run into this problem if you have an anonymous user defined on your database.
"When a client tries to connect to the database, the MySQL server looks through the rows in the user table in a sorted order.
The server uses the first row that matches the most specific username and hostname."
Delete the anonymous user and try again.

How to execute queries in remote servers

I am trying to insert data to a web site from the code of another web site. How can I use the mysql_connect() command for that. Can I use the IP address of the first web site in the second web site code?
Please help me
Yes, you can use a remote MySQL server with mysql_connect(). Use mysql_connect() according to the PHP manual (http://php.net/manual/de/function.mysql-connect.php) and use your server's IP as $server. However, make sure the MySQL port is accessible from remote on the MySQL server (port 3306).
For inserting data in the database you need to connect the database
Selecting DATABASE
you need to just connect the server on which the db exist in which we are inserting
<?php
$link = mysql_connect('ip or server of the db in which inserting', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make myDB the current database
$db_selected = mysql_select_db('myDB', $link);
if (!$db_selected) {
die ('Can\'t use myDB: ' . mysql_error());
}
?>
for inserting records in another website , you need to just connect the server and DB of that particular website, and fire Queries.
let me know if more..

Trouble with PHP mysql_select

Ok, I've just started learning php, and for some reason the mysql_connect() and mysql_select_db() do not appear to connect to the database.
I also need a good example of a mysql table, as I am not sure what to put in my table. How do I manage to connect my site to the database?!
Here is the code I am using in my connect.php page.
<?php
//not working
$connect = mysql_connect('localhost',
'myuser', 'password', 'mypass')
or die("This function should work.");
//still a lingering error
$db_select = mysql_select_db("mydbname", $connect);
?>
If you just start with PHP then a good idea would be to get Apache and MySQL on your own computer. There are plenty of easy installable packages like WAMP (http://www.wampserver.com/en/). There are examples and HOWTOs there. The good in this package, is that there is a PHPMyAdmin that comes packed, and you can use it to make a sample table, or just to play around.
Next, for the concrete code, there is a nice example at the PHP documentation site (http://php.net/manual/en/function.mysql-connect.php).
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>
When using the local server you can use the ROOT user in MySQL. For a test table you can make one called, for example friends, with two VARCHAR fields for name and phone number. And you can play around to list them edit them and so on.
Good luck.

unable to connect to mySQL Db

I am a newbie to PHP and to the net world, and trying to connect to a mySQL Db using this PHP code:
<?php
echo "Hello World \n";
$mysql_host = "MySQL Host"; // this is what specified to use in mySQL management page at my host
$mysql_database = "mysql_database";
$mysql_user = "mysql_user";
$mysql_password = "mysql_password";
echo $mysql_host;
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($mysql_database);
if (!$db_selected) {
die ('Can\'t use '.$mysql_database.' : ' . mysql_error());
}
?>
please, what can be wrong with this code? I couldn't find any syntax error and still - I am not able to connect to the Db
can it be and the problem is related to the host only?
The following variables should contain values that are respectively:
$mysql_host - IP or host name of the server with your database,
$mysql_database - name of the database,
$mysql_user - name of the database user,
$mysql_password - password for specific user to the specific database,
Make sure all of them are correct and then the problem should be resolved. If it is not, let us know.
If you are actually typing MySQL Host in your code, then you're not providing a valid hostname. You should try with localhost instead.
Otherwise, you current host must have provided you with the needed information.
You should also tell us what error your script gives you, when it dies. That enables us to give a qualified answer instead of guessing.
as #Michael says,
$mysql_host = "MySQL Host";
is definitely wrong, that field must have a either a valid host/socketname or localhost..
These guys are spot on. Also, the password is usually blank on a localhost program.
But, this is just something I noticed:
Your $conn variable is missing an 'n' in your 'if' statement.
You are storing connection in $conn but in if condition you are checking with ($con).
(There might be other errors. But I can see this error)

Categories