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

i created a simple db connection in my php page and its working fine since its not showing any error while executing this
<?php
$link = mysql_connect('www.ccccccccccccc.co.uk', 'cccccccccc', 'accccc');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
/*echo 'Connected successfully';*/
echo "DB : <font color='green'>ACTIVE</font>";
mysql_close($link);
?>
The problem is the page is showing error Access denied for user 'root'#'localhost' (using password: NO) while executing
<?php
$q = mysql_query("SELECT slno, name, idno FROM $memlist") or die(mysql_error());
echo "<table><tr><th> NO</th><th> NAME</th>
<th> ID NO</th></tr>";
while($row = mysql_fetch_array($q)){
extract($row);
echo "<tr><td>$slno</td><td>$name</td>
<td>$idno</td></tr>";
}
echo"</table>";
?>
i am working on server directly not on local host

You don't appear to be connecting to the database in the second piece of code, so it's trying to connect with default settings (which obviously won't be correct due to security concerns).
As for the first block of code, you're closing the connection immediately after opening it, which is kind of pointless.

Related

fix access denied for root'#'localhost' (using password: NO) in init.php on line 2

I have an e-commerce website, and I m trying to move from localhost windows to Linux Mint. the problem is that I can't connect to database.
I see my config.inc.php in lampp/phpmy admin and the username is root and password = ""
I don't know how to fix this.
<?php
$db = mysqli_connect('127.0.0.1', 'root', '', 'ecommerce');
if(mysqli_connect_errno()) {
echo 'Database connection failed with following errors: '.mysqli_connect_error();
die();
}
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/config.php';
require_once BASEURL.'helpers/helpers.php';

I cant connect to my MYSQL Database using Php

Hi i have a problem connecting with my Mysql database i have the following code:
<?php
$servername = "dt5.ehb.be";
$username = "TVOSAPP";
$password = "*****";
$dbname = "TVOSAPP";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT storyId, title, score FROM Stories";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["storyId"]. "Naam" . $row["title"]. "score" . $row["score"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
which gives the following error:
Connection failed: Access denied for user 'TVOSAPP'#'10.3.101.30' (using password: YES)
I hope you can help me out to solve this problem it would be very much appreciated
the user that you are trying to connect with might not have the permission to connect remotely to the DB. please verify the same. To give remote access you might need to run
grant <privilage name> on TVOSAPP.* to 'TVOSAPP'#'<youripaddress>' identified by <yourpassword>
Ref: http://dev.mysql.com/doc/refman/5.7/en/grant.html
EDIT:
If your IP address is not static then you can use a percentage sign (%) in place of your IP address. However this approach is less secure as it allows any host to connect to the database remotely.
I fixed it about a week ago is had a space too much thats why I couldn't connect thank you all for your responses

mysql Access denied for user 'www-data'#'localhost'

I have ran into a wall with trying to connect to my site now it worked fine till I added a shoutbox but I don't think it has caused it to run into a Access denied for user 'www-data'#'localhost' (using password: NO).
I have several sites running and only this one site seems to be running into this problem I have reset password and still no luck please someone help me.
config.php
$site_settings['mysql_host'] = "localhost";
$site_settings['mysql_user'] = "root";
$site_settings['mysql_pass'] = "PasswordHash";
$site_settings['mysql_db'] = "project";
cms.php
function dbconn()
{
global $site_settings;
if (!#mysql_connect($site_settings['mysql_host'], $site_settings['mysql_user'], $site_settings['mysql_pass']))
{
switch (mysql_errno())
{
case 1040:
case 2002:
if ($_SERVER['REQUEST_METHOD'] == "GET")
die("<html><head><meta http-equiv='refresh' content=\"5 $_SERVER[REQUEST_URI]\"></head><body><table border='0' width='100%' height='100%'><tr><td><h3 align='center'>The server load is very high at the moment. Retrying, please wait...</h3></td></tr></table></body></html>");
else
die("Too many users. Please press the Refresh button in your browser to retry.");
default:
die("[" . mysql_errno() . "] dbconn: mysql_connect: " . mysql_error());
}
}
mysql_select_db($site_settings['mysql_db'])
or die('dbconn: mysql_select_db: ' . mysql_error());
mysql_set_charset('utf8');
}
screenshot - http://prntscr.com/b7nnc7
P.S I have gotten error_reporting(E_ALL); intact also.

mysql_connect access denied error when trying to access remote database

I'm trying to connect to a remote database. Here's my code:-
php $con = mysql_connect("2toria.com","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("myTable", $con);
$result = mysql_query("SELECT * FROM Contestants");
while($row = mysql_fetch_array($result)) { echo $row['Name']; echo "<br />"; }
mysql_close($con);
The database, table, username and password names are all correct (I've changed them here for obvious reasons), but I'm getting the following error:-
Warning: mysql_connect() [function.mysql-connect]: Access denied for
user 'username'#'bluechip6.ukhost4u.com' (using password: YES) in
/home/toriaco/public_html/bigbro/index.php on line 9 Could not
connect: Access denied for user 'username'#'bluechip6.ukhost4u.com'
(using password: YES)**
First possible reason:
I know antagonist (a Dutch hosting service) blocks all connections that are not from localhost for security reasons, and I don't think they are the only ones. (So always connect to localhost, not a http://... URL!)
Second possible reason:
The password/username is wrong.

MySQL failing to establish a connection

I recently created a webpage, while using an usbWebserver, so basically a local server.
Yesterday, I have purchased a domain and hosting, and I wanted to move my files onto the server.
I have changed my username, password and url, however I cannot get the mysql_connect to work.
<?php
$mysqlhost = "mysql04.totaalholding.nl";
$user = "a";
$passwd = "";
$mysql = mysql_connect($mysqlhost, mysql_real_escape_string($user), mysql_real_escape_string($passwd));
if (!$mysql) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('a_turfjes', $mysql);
if (!$db_selected) {
die('Could not connect: ' . mysql_error());
}
?>
The above code is how I connect to the database, which should work. (please note that a is not my username and neither is my password empty).
These are the properties of the database:
DATABASE: a_turfjes
Extern MySQL Host: mysql04.totaalholding.nl
Users: a_admin
I am not quite sure which username to use should I use the username and password from cpanel (which is required to access PHPMyAdmin), or the username and password, which is the user of the database itsself.
I'd like some help on this error. When accessing my index.php (which includes db.php (which is the file above)), I receive the following errors:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'root'#'localhost' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'root'#'localhost' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/a/public_html/turfjes/db.php on line 8
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'#'www30.totaalholding.nl' (using password: NO) in /home/a/public_html/turfjes/db.php on line 8
Could not connect: Access denied for user 'root'#'www30.totaalholding.nl' (using password: NO)
Use the username and password of the database itself not the cpanel.
Test connection using:
$mysql_host = "localhost"; # Usually doesn"t need modified
$mysql_db = "a_turfjes"; # Database name
$mysql_user = ""; # Username
$mysql_pass = ""; # Password
$link = mysql_connect ($mysql_host,$mysql_user,$mysql_pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
If successful, access records:
$query = "SELECT * FROM TableName";
$result = mysql_db_query ($dbname, $query, $link);
Use the database username and password. If the database is hosted in another server please give the host name to that server name