gillrowley
Programmer
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
<?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