1
votes

I'm completely new to php and mySQL and 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 "
"; }

mysql_close($con);

The database, table, username and password names are all correct (Ive 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)**

Any ideas on the problem? TIA, Matt

1
This looks normal: hosting providers usually close mySQL databases for external connections for security reasons. Is the database explicitly supposed to be accessible? - Pekka
Yes, and it's not an external connection, it's part of the hosting I've got, so I should be able to access it. I can use the same username and password credentials with the MYSQL GUI tools and get to my database that way. What I need to do is query the database and return rows, as shown. - Mat Richardson
Then why don;t you connect to "localhost" instead of "2toria.com"? - 11684

1 Answers

3
votes

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.