database access problem - mysql_connect()
Moderator: General Moderators
database access problem - mysql_connect()
I have this PHP I've been working on to access my database and I can't seem to get past this error:
Warning: mysql_connect(): Access denied for user 'quotes@82.'@'82.197.130.21' (using password: YES) in /home/www/quotes.mypressonline.com/aaaTest.php on line 28
Access denied for user 'quotes@82.'@'82.197.130.21' (using password: YES)
Here is my code, and notice the difference from above: user 'quotes@82.'@'82.197.130.21' as opposed to below:
'quotes@82.197.130.21'
<?php
// mysql config
$db = mysql_connect("fdb1.runhosting.com:3306", "quotes@82.197.130.21", "DBpw");
if (!$db) { die( mysql_error() ); }
// open "quotes", as current db
$db_selected = mysql_select_db("quotes", $db);
if (!$db_selected) { die ( mysql_error() ); }
$result = mysql_query("SELECT * FROM quotes WHERE AuthorFirst=First and AuthorLast=Last", $db_selected) or die( mysql_error() );
$num_rows = mysql_num_rows($result) or die( mysql_error() );
$i=0;
while ($i < $num_rows) {
$quote = mysql_result($result,$i,"Quotes");
$first = mysql_result($result,$i,"AuthorFirst");
$last = mysql_result($result,$i,"AuthorLast");
echo "$quote<br>-$first $last<br><br>";
$i++;
}
// close database
mysql_close($db) or die( mysql_error() );
?>
Your help is much appreciated, thank you,
Nate
Warning: mysql_connect(): Access denied for user 'quotes@82.'@'82.197.130.21' (using password: YES) in /home/www/quotes.mypressonline.com/aaaTest.php on line 28
Access denied for user 'quotes@82.'@'82.197.130.21' (using password: YES)
Here is my code, and notice the difference from above: user 'quotes@82.'@'82.197.130.21' as opposed to below:
'quotes@82.197.130.21'
<?php
// mysql config
$db = mysql_connect("fdb1.runhosting.com:3306", "quotes@82.197.130.21", "DBpw");
if (!$db) { die( mysql_error() ); }
// open "quotes", as current db
$db_selected = mysql_select_db("quotes", $db);
if (!$db_selected) { die ( mysql_error() ); }
$result = mysql_query("SELECT * FROM quotes WHERE AuthorFirst=First and AuthorLast=Last", $db_selected) or die( mysql_error() );
$num_rows = mysql_num_rows($result) or die( mysql_error() );
$i=0;
while ($i < $num_rows) {
$quote = mysql_result($result,$i,"Quotes");
$first = mysql_result($result,$i,"AuthorFirst");
$last = mysql_result($result,$i,"AuthorLast");
echo "$quote<br>-$first $last<br><br>";
$i++;
}
// close database
mysql_close($db) or die( mysql_error() );
?>
Your help is much appreciated, thank you,
Nate
- EverLearning
- Forum Contributor
- Posts: 282
- Joined: Sat Feb 23, 2008 3:49 am
- Location: Niš, Serbia
Re: database access problem - mysql_connect()
Did you try connecting with:
?
Code: Select all
$db = mysql_connect("fdb1.runhosting.com:3306", "quotes", "DBpw");
Re: database access problem - mysql_connect()
Goto mysql console and see what grants you have for quotes.
Code: Select all
SHOW GRANTS FOR 'quotes'@'fdb1.runhosting.com';
SHOW GRANTS FOR 'quotes'@'82.197.130.21';Re: database access problem - mysql_connect()
Well, I've tried $db = mysql_connect("fdb1.runhosting.com:3306", "quotes", "DBpw"); and now every combination I can think of for the host and username, no luck there...
I also tried
SHOW GRANTS FOR 'quotes'@'fdb1.runhosting.com';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'mysql'
SHOW GRANTS FOR 'quotes'@'82.197.130.21';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'mysql'
as well as a few others
SHOW GRANTS FOR '87604_quotes'@'82.197.130.21';
Result: #1141 - There is no such grant defined for user '87604_quotes' on host '82.197.130.21'
SHOW GRANTS FOR '87604_quotes'@'fdb1.runhosting.com';
Result: #1141 - There is no such grant defined for user '87604_quotes' on host 'fdb1.runhosting.com'
GRANT SELECT ON `quotes` . * TO 'root'@'%';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'quotes'
Good ideas anyway, will resetting the GRANT permission fix this with that result message? I'm off to try that now, if it works I'll post what I did here, but in the meantime if you have any more suggestions I'd like to hear them.
Thanks, Nate
I also tried
SHOW GRANTS FOR 'quotes'@'fdb1.runhosting.com';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'mysql'
SHOW GRANTS FOR 'quotes'@'82.197.130.21';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'mysql'
as well as a few others
SHOW GRANTS FOR '87604_quotes'@'82.197.130.21';
Result: #1141 - There is no such grant defined for user '87604_quotes' on host '82.197.130.21'
SHOW GRANTS FOR '87604_quotes'@'fdb1.runhosting.com';
Result: #1141 - There is no such grant defined for user '87604_quotes' on host 'fdb1.runhosting.com'
GRANT SELECT ON `quotes` . * TO 'root'@'%';
Result: #1044 - Access denied for user '87604_quotes'@'%' to database 'quotes'
Good ideas anyway, will resetting the GRANT permission fix this with that result message? I'm off to try that now, if it works I'll post what I did here, but in the meantime if you have any more suggestions I'd like to hear them.
Thanks, Nate
Re: database access problem - mysql_connect()
You'll need to login as mysql admin to access the mysql database and use the GRANT statement to grant privileges to a user.
Or if you're using a control panel like CPanel, Plesk etc, you can do it there.
Or if you're using a control panel like CPanel, Plesk etc, you can do it there.
Code: Select all
GRANT ALL ON databaseName.* TO 'username'@'localhost';
GRANT ALL ON databaseName.* TO 'username'@'%';Re: database access problem - mysql_connect()
I tried messing with the GRANT settings on the mysql server and I could not get any access or change any permission settings as far as I can tell I have SELECT and PROCESS and that's it. hmmmm. Do you see anything wrong with the code? Thanks a bunch, Nate
Re: database access problem - mysql_connect()
<html>
<body>
<?php
$con = mysql_connect("localhost:3306","root","root");
if (!$con)
{
echo "BAG";
echo ("Could not connect: ") . mysql_error();
}
mysql_select_db("<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>", $con);
$result = mysql_query("SELECT * FROM pet");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['owner']. " " . $row['species']. " " . $row['sex'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>
----------------------------------
when i am browsing this page as http://localhost/db_connect.php, blank page is showing with no errors.
Can anyone solve the issue?
<body>
<?php
$con = mysql_connect("localhost:3306","root","root");
if (!$con)
{
echo "BAG";
echo ("Could not connect: ") . mysql_error();
}
mysql_select_db("<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>", $con);
$result = mysql_query("SELECT * FROM pet");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['owner']. " " . $row['species']. " " . $row['sex'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>
----------------------------------
when i am browsing this page as http://localhost/db_connect.php, blank page is showing with no errors.
Can anyone solve the issue?
Re: database access problem - mysql_connect()
Code: Select all
<html>
<body>
<?php
$con = mysql_connect("localhost:3306", "root", "root");
if (!$con)
{
echo "BAG";
die("Could not connect: ") . mysql_error();
}
mysql_select_db("smurf", $con) or die("Couldnt select database");
$result = mysql_query("SELECT * FROM pet");
if (mysql_num_rows($result) == 0)
echo "No rows to display";
else
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['owner']. " " . $row['species']. " " . $row['sex'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>