Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB connection in PHP

Status
Not open for further replies.

gillrowley

Programmer
Apr 2, 2004
59
US
I'm very new to PHP and am trying to connect to a database. I establish a connection to MySQL, but I get an error and don't know why, I'm following all the code I find on various tutorials:

<?php
// connect to the database
$dbhost = 'localhost';
$dbuser = 'dbuser';
$dbpass = 'mypass';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or
die ('Error connecting to mysql');

$dbname = 'my_mysql_database';
mysql_select_db($dbname);

$query = "SELECT userID, lastName, firstName FROM users";
$result = mysql_query($query) or die(mysql_error());

etc...
The error that is returned on my web page is:

No Database Selected

If I leave off the die(mysql_error()) it errors out when I try to return a recordset, so for some reason it doesn't seem to be finding my database. Any ideas? I've spelled everything correctly as far as db names, passwords, etc are concerned. Thanks.
Gill
 
try this to get more error info
Code:
mysql_select_db($dbname) or die(mysql_error());
 
Appears to be a rights issue:

Access denied for user: 'dbuser@localhost' to database 'my_mysql_database'

I'll contact the ISP. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top