+ Reply to Thread
Results 1 to 3 of 3

Thread: Problem selecting database with PHP

  1. #1
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Problem selecting database with PHP

    currently attempting to learn the basics of MySQL and PHP, which was going OK until I wanted to connect to a database.

    I've created a database and put in some tables, set up a user with username and password, all through MySQL and phpMyAdmin.

    I've two PHP files, the first storing the usual:
    <?php
    $db_host='localhost';
    $db_database='stevet70_test';
    $db_username='stevet70_test';
    $db_password='password';
    ?>

    the second doing the connecting and selecting:
    <?php
    // Include our login information
    include('db_login.php');
    // Connect
    $connection = mysql_connect($db_host, $db_username, $db_password);
    if (!$connection){
    die ("Could not connect to the database: <br />". mysql_error( ));
    }
    // Select the database
    $db_select=mysql_select_db($db_database);
    if (!$db_select)
    {
    die ("Could not select the database: <br />". mysql_error( ));
    }
    ?>

    I've actually tried going through the whole process on two different hosting accounts. The PHP files are on the same hosting as the database, but all I get is:

    Could not select the database:
    Access denied for user 'stevetur_test'@'localhost' to database 'stevetur_test'

    Where am I going wrong?

    I've also tried putting in the wrong password, which gives a much longer error message, suggesting that I'm connecting to MySQL OK, it's just the actual database.

    Any help much appreciated

  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: Problem selecting database with PHP

    in cpanel, under the mysql section, did you give the user permission to access the database? you should have seen a page of selection boxes.

    take a look at this page for more information: http://wiki.jumba.com.au/wiki/MySQL_...er_to_database
    Last edited by xPlozion; 01-05-2009 at 03:20 PM.

  3. #3
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Re: Problem selecting database with PHP

    Thank you!
    Hoped it was something simple I'd missed, I created the user but hadn't clicked on "Add" to add the user to that specific database - which gave me the page with all the selection boxes.

    Problem solved

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Joomla Extensions PHP Problem.
    By shazaani in forum Free Hosting
    Replies: 2
    Last Post: 11-20-2008, 05:16 AM
  3. problem with finding my mysql database (PHP)
    By wikiadmin in forum Free Hosting
    Replies: 1
    Last Post: 06-29-2008, 03:48 PM
  4. php problem
    By himgar in forum Free Hosting
    Replies: 1
    Last Post: 02-22-2008, 02:41 AM

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