cannot connect to database
Posted by: carl (---.bulldogdsl.com)
Date: March 03, 2006 06:30PM

Hi I have just started to learn WAMP and have created a database with one table, i have created a php script to connect to DB and a simple form to enter info into the table however I get an error when I run the script, this outputs the error message in the script; couldn’t select database from the code.

$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server"winking smiley;
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database"winking smiley;

I think the first part is ok but I don’t know what is wrong the database exists and I have double checked all name and spellings i.e. username and database name ect.

Does anyone have any ideas as to what Im doing wrong/what going wrong?

Thanks in advance for any help you can give me.


Options: ReplyQuote
Re: cannot connect to database
Posted by: schnoodles (---.diverse-projects.net)
Date: March 04, 2006 07:01AM

try or die(mysql_error()); on both of the mysql functions and it will give you a more in depth error for what you are getting.

Options: ReplyQuote
Re: cannot connect to database
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: March 04, 2006 10:31AM

this means there was a problem connection to the database. When you use die() for error code, it outputs your custom error code instead of displaying php normal errors. remove the or die() parts from your scripts, and try again. you should get a more detailed error message. if you still need help post here the error you get.

also remember that the default mysql login settings for mysql are the user root with no password, so if you have not changed roots password, use this:

$connection = mysql_connect ( $host, $user, '' ) or die ("couldn't connect to server"winking smiley;

Options: ReplyQuote


Sorry, only registered users may post in this forum.