Cannot connect to database

ConnorMcLeod

New Member
Messages
21
Reaction score
0
Points
0
Hi all,

I took the following steps to prepare my first MySQL database and tried to access it from PHP.
1) used MySQL(R) Database to create a database
2) created PHP script to first connect to localhost
and then select database as below.
mysql_select_db($dbname) or die ('Error selecting database');

There was no error connecting to the host,
but system "Error selecting database" to me.

$dbname is the same name as shown in MySQL Database , also the same as in the left panel of PHPMyAdmin (this is the only database I created, and there is a default (?) database named information_schema).

Is there anything else I need to do?

The full PHP code i used to connect and select database is below.

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql server');
mysql_select_db($dbname) or die ('Error selecting database');
mysql_close();

Please help. I am new to PHP and stuck.
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
Did you add the user you are connecting with to the database?
 

maxyes

New Member
Messages
24
Reaction score
0
Points
0
Also remember the capitals. Also remember that the user database is "websitename"_"name" and the database is "websitename"_"databasename".
 

ConnorMcLeod

New Member
Messages
21
Reaction score
0
Points
0
Think I probably didn't add the user to the database properly. Removed user and database, and repeated all steps again seem to solve the problem.

Silly mistake for first trial :hahano:
 
Top