Forum Moderators: coopster
[code]
mysql_connect ("localhost", "database", "****") or die (mysql_error());
mysql_select_db ("dotan_stats");
$query = "TOP SECRECT QUERY!";
$result = mysql_query($query);
print "\n<!-- ".mysql_error()." -->";
[code]
And I get this in my HTML code:
<!-- No Database Selected -->
Does anybody see anything obvious that would cause it not to connect? Where can I begin to debug?
Dotan
[edited by: coopster at 12:47 pm (utc) on July 21, 2005]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]
adding "or die (mysql_error())" to all of your queries and database interaction functions while in development is the way to go but...
another thing is if you have many of them on one page it can be somewhat frustrating to find whodunnit, so
add a little text to each
or die ("connect died: " . mysql_error())
or die ("select db died: " . mysql_error())
or die ("query1 died: " . mysql_error())
and so on
print "\n<!-- ".mysql_error()." -->";
I do that because I don't want the script to die- I'm forced to test this on a live site. So I just output it in HTML comments. And I know exactly where it is, so I do not need anything fancy.
But what would prevent it from connecting?
Thanks.
Dotan
[edited by: coopster at 7:05 pm (utc) on July 21, 2005]
[edit reason] no urls per TOS [webmasterworld.com] [/edit]
Are you sure that the php pages you are saving are on the same physical server as mysql database? i mean for example you have a virtual host or your code is on another server then mysql then first of all "localhost" won't work or even if i both the things are on same server as is the case most of the time, then check for user permissions.
I might be wrong but i notice a small thing which might be the problem and no one else noticed
mysql_connect ("localhost", "database", "****") or die (mysql_error());
mysql_select_db ("dotan_stats");
you are putting "database" in place where you need to specify username for mysql db, is that a valid mysql user on your server?
do you have a valid MySql user 'database'?
well, ok if it is, then check for permissions for this user, is that user allowed to connect to your stats database?
I think this is for sure Permissions Problem, either host permissions or user permissions.
Thank You
Kami