PDA

View Full Version : problem connecting to database


earthman
01-02-2007, 07:09 AM
Hello all,

Im a fairly competent PHP programmer and new to monster. I am using a very simple db connect script below to access my db. Ive used this script for years with various hosts with no probs. Just wondering if im missing something regarding monster:

<?php

$db = mysql_connect("localhost", "prefix_user", "password");



mysql_select_db("prefix_database",$db);

?>

I really cant see what is going wrong. All the info is correct, no spelling mistakes etc but i always get "No database selected."

Please help!!!!

godrockzzz
01-02-2007, 08:24 AM
This is what i use, it always works. Besides that i could check to make sure you've assigned the user to the database

<?php
$link = mysql_connect ("localhost", "prefix_user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("prefix_database") or die("Could not select database");
?>

Seb
01-02-2007, 09:08 AM
Yeah, use
or die(mysql_error());
to detect errors.
Most likely, "prefix_user", "password" or even "prefix_database" is either empty or not correct.

earthman
01-02-2007, 09:48 AM
Cheers for that. I didnt assign the user to database, i really should be ashamed of myself!
:rolleyes: