Page 1 of 1

Problems...accessing database

Posted: Tue Dec 08, 2009 1:05 am
by bob09
Hello All,

I having trouble accessing a database on another server.

Here is my code

Code: Select all

 
<?php
 
$conn = mysql_connect('localhost','falldb_TX','austin') or die("Cannot connect to database");
 
if($conn)
{
echo "Connected successfully<br>";
}
else
{
echo "Connection not established<br>";
}
 
mysql_select_db('falldb_TX') or die(mysql_error());
echo "Connected to database";
 
$result = mysql_query("SELECT * FROM Students", $conn) or die (mysql_error());
$num = mysql_numrows($result);
 
mysql_close($conn);
 
$i = 0;
while ($i < $num)
{
$banner=mysql_result($result, $i, "Banner");
$first=mysql_result($result, $i, "First Name");
$last=mysql_result($result, $i, "Last Name");
$address=mysql_result($result, $i, "Street Address");
 
echo "<b>$banner</b> First: $first <br> Last: $last <br> Address: $address<br>";
 
$i++;
}
 
?>
 
 
 
Currently I am getting the following output:

Code: Select all

 
You're connected.
Access denied for user ''@'localhost' to database 'falldb_tx'
 
When I add the username and password I get this message:

Code: Select all

 
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'falldb_TX'@'localhost' (using password: YES) in C:\wamp\www\Project\dbConfig.php on line 3
Cannot connect to database
 
I am really confused. It seems that if I don't supply a password then i'm connected, but cannot access the database. It fails at the line (mysql_select_db("falldb_TX"). Or if I supply a username AND a password I cannot connect at all.

If someone can please give me some pointers that would be great.

Thanks.

Re: Problems...accessing database

Posted: Tue Dec 08, 2009 1:34 am
by Weiry
check your database server has the username/password your trying to connect with and that they have the correct permissions to access the database

Re: Problems...accessing database

Posted: Tue Dec 08, 2009 1:59 am
by bob09
Weiry wrote:check your database server has the username/password your trying to connect with and that they have the correct permissions to access the database
Thank you for responding. The server is maintained by my teacher (its a hmwk assignment) and he told me that I don't need to worry about the permissions because everything was set up correctly. He also said that its probably something that I'm doing wrong.

Currently I am using WAMPServer (my laptop has Windows Vista) and for the life of me, I can't figure out what's wrong!

Re: Problems...accessing database

Posted: Tue Dec 08, 2009 2:01 am
by bob09
bob09 wrote:
Weiry wrote:check your database server has the username/password your trying to connect with and that they have the correct permissions to access the database
Thank you for responding. The server is maintained by my teacher (its a hmwk assignment) and he told me that I don't need to worry about the permissions because everything was set up correctly. He also said that its probably something that I'm doing wrong.

Currently I am using WAMPServer (my laptop has Windows Vista) and for the life of me, I can't figure out what's wrong!
Also I know the username and password are correct because when I supply them I can access my teachers server and access my database and tables.