Problem using Dreamweaver to connect to MySQL database

Discussion in 'Web Design and Development' started by jh100000, Feb 21, 2006.

  1. macrumors newbie

    Joined:
    Feb 11, 2005
    Location:
    London, UK
    #1
    I'm completely new to web database programming and I'm trying to do the equivalent of a 'hello world' application - i.e. all I want to do is create a page that will magically pull some data from a database (proof of concept if you like).

    So I've got Dreamweaver, I've got MySQL setup and I've created a database and a few tables and put a bit of data into them.

    When I try to create a connection one of two things happens...

    If I specify a valid username/password combination I get error 1045 Access Denied for user....

    Or, If I just specify any old username and no password I get two databases (not mine) 'information_schema' and 'test' which I can happily query.

    But i want to query my database.....
     
  2. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    Where have you set up the new MySQL database? Have you specified your php script to use that server?

    I may also help if you post the code from the php file (use the php tags)... ;)

    Edit: In particular the database info, like this:

    PHP:
    $DB_Host="whatever.server.domain";
    $DB_Name="your_database";
    $DB_User="db_user";
    $DB_Pass="******";

    $link mysql_connect($DB_Host$DB_User$DB_Pass);
    and the queries
    PHP:
    $query "SELECT whatever FROM table WHERE something matches";
    $result mysql_db_query($DB_Name$query$link);
     
  3. macrumors 68030

    superbovine

    Joined:
    Nov 7, 2003
    #3
    just another way with different type of error checking. The php script will die if doesn't connect the db.

    PHP:
    //connect to the database server

        
    define('DB_USER''user name');
        
    define('DB_PASSWORD''password here');
        
    define('DB_HOST','localhost or addy');
        
    define('DB_NAME''db name');

          
    //@ turns off messages
        
    $dbc = @mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
        
        if(!
    $dbc) {
          die( 
    '<p>Unable to connect to the ' .
            
    'database server at this time. </p>' );

        }

        if(! @
    mysql_select_db(DB_NAME) ) {
          die( 
    '<p>Unable to locate the DB_NAME ' .
            
    'database at this time.</p>' );
        }


    ?>
     

Share This Page