Closed Thread
Results 1 to 6 of 6

Thread: can not connect to database

  1. #1
    dskamburapola15 is offline x10Hosting Member dskamburapola15 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    4

    can not connect to database

    i tried to connect database from my web page with following code.

    $host=\"localhost\";
    $username=\"dsk123_test\";
    $password=\"789\";
    $db_name=\"dsk123_dsk\";

    mysql_connect(\"$host\", \"$username\", \"$password\")or die(\"cannot connect to server\");
    echo \"Host - Connected - OK <br><br>\";
    mysql_select_db(\"$db_name\")or die(\"cannot select DB\");
    echo \"Database - Connected - OK <br><br>\";

    It display following messages.

    Host - Connected - OK

    cannot select DB

    How to fix this.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: can not connect to database

    Code:
    
    $link = mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
    echo "Host - Connected - OK <br><br>";
    mysql_select_db("$db_name" , $link )or die("cannot select DB. Reason: " . mysql_error( $link ));
    echo "Database - Connected - OK <br><br>";
    Try the above edits to your code.
    Always check the error message given by the DB .

    You did remember to connect the specific user to the specific database in MySQL Databases and to give it ALL PRIVILIGES ?
    Nothing is always absolutely so.

  3. #3
    dskamburapola15 is offline x10Hosting Member dskamburapola15 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    4

    Re: can not connect to database

    thanks. I tried your code.
    But I got following error.

    cannot select DB. Reason: Access denied for user 'dsk123_test'@'10.33.248.%' to database 'dsk123_dsk'

    what to do.

  4. #4
    stpvoice's Avatar
    stpvoice is offline Community Support Rep stpvoice has a brilliant futurestpvoice has a brilliant futurestpvoice has a brilliant future
    Join Date
    Dec 2008
    Location
    United Kingdom
    Posts
    5,939

    Re: can not connect to database

    Hello,

    Did you add the user to the database as descalzo said before?
    Are you trying to connect from a file on your x10 account?

    Thanks.


  5. #5
    dskamburapola15 is offline x10Hosting Member dskamburapola15 is an unknown quantity at this point
    Join Date
    May 2011
    Posts
    4

    Re: can not connect to database

    Quote Originally Posted by stpvoice View Post
    Hello,

    Did you add the user to the database as descalzo said before?
    Are you trying to connect from a file on your x10 account?

    Thanks.
    how to give privileges to user. there is no privileges tab in phpMyAdmin

  6. #6
    stpvoice's Avatar
    stpvoice is offline Community Support Rep stpvoice has a brilliant futurestpvoice has a brilliant futurestpvoice has a brilliant future
    Join Date
    Dec 2008
    Location
    United Kingdom
    Posts
    5,939

    Re: can not connect to database

    Hello,

    Please see this page: http://x10hosting.com/wiki/How_to_Cr...abase_and_User
    Scroll down to "Creating only a user" and "Adding a user to a database".

    Thanks.


Closed Thread

Similar Threads

  1. Replies: 3
    Last Post: 05-22-2010, 07:04 AM
  2. Replies: 2
    Last Post: 03-17-2010, 04:51 PM
  3. Replies: 3
    Last Post: 02-08-2010, 04:24 PM
  4. Replies: 4
    Last Post: 01-07-2010, 09:16 AM
  5. Replies: 0
    Last Post: 11-22-2008, 05:53 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