+ Reply to Thread
Results 1 to 5 of 5

Thread: Cannot connect to database

  1. #1
    ConnorMcLeod is offline x10Hosting Member ConnorMcLeod is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    21

    Cannot connect to database

    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.

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Cannot connect to database

    Did you add the user you are connecting with to the database?

  3. #3
    maxyes is offline x10Hosting Member maxyes is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    24

    Re: Cannot connect to database

    Also remember the capitals. Also remember that the user database is "websitename"_"name" and the database is "websitename"_"databasename".

  4. #4
    ConnorMcLeod is offline x10Hosting Member ConnorMcLeod is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    21

    Re: Cannot connect to database

    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:

  5. #5
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: Cannot connect to database

    Glad you figured it out. Always here to help out

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2008, 01:38 PM
  2. Replies: 3
    Last Post: 04-11-2008, 12:27 PM
  3. cant connect to DATABASE
    By mo_patel in forum Free Hosting
    Replies: 9
    Last Post: 09-22-2007, 06:49 PM
  4. Could not connect to MySQL database?
    By chiamingen in forum Free Hosting
    Replies: 4
    Last Post: 03-16-2005, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers