[svlug] Book recommendation

Erik Steffl steffl at bigfoot.com
Sun Jul 10 21:57:31 PDT 2005


Karsten M. Self wrote:
> on Thu, Jul 07, 2005 at 05:55:00PM -0700, Bill Hubbard (kwooda at netzero.net) wrote:
...
>>Where I got stuck was following an example in one of my books that 
>>showed how to connect to a database.  The code was as follows (the 
>>first two lines, anyway):
>>
>>mysql_connect("localhost", "nobody", "password") or
>>   die ("Could not connect to database.");
>>
>>All I ever get when I access this page is, "Could not connect to 
>>database".  No clue as to why.  Are there, like, LOG FILES anywhere?

   (only saw this now, sorry if this was already answered)

   those two lines are really really BAD. You're not looking for logs, 
you're looking for mysql_connect return code and/or other error 
reporting facilities (inside of the program).

   I assume that those two lines are PHP (could be perl but then you'd 
probably be using DBI), something like this should help to figure out 
what's going on:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

   found at http://us3.php.net/mysql_connect (I would add printing of 
the host, database and username (not password:-) to make troubleshooting 
easier)

   I don't do php so I can't point you to good docs/tutorials but I 
suggest to look for a better book that the one you got that example from.

   In general - always get all the relevant error info and print it out.

	erik




More information about the svlug mailing list