Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2003
    Posts
    19

    Unanswered: Cannot Connect to a database

    I am using php to create the script for doing for creating a login program. Being new to this, I copied mysql database to the server. The database is called clamps and I have a text file customers. There are two three more files, frm, myd, and myi.

    now the code

    Code:
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
    
    mysql_select_db($db,$connection) or die ("Unable to select database!");
    provides the message "Unable to select database!". The code before that connects to mysql and all is ok. Can any body stear me in the right direction?

    Richad M

  2. #2
    Join Date
    Mar 2004
    Location
    Somewhere
    Posts
    21
    I use if ($dbc = @mysql_connect ('localhost' , '$user' , '$password')) //connect to database

    {

    if (!@mysql_select_db ('$database'))

    {

    die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>'); //produce error if could not connect to database

    }

    } else {

    die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>'); //produce error if could not connect

    }

    // I am a complete newb at php/mysql but it seems to work for me
    :P Daz
    CU Blitz

  3. #3
    Join Date
    Aug 2003
    Posts
    19
    Thanks, I will try this and see what error messages I get.

    Richard M

  4. #4
    Join Date
    Aug 2003
    Posts
    19
    I just ran the code and I understand now its not the code but access denied on the server. This will help get me access to the server.

    Richard M

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Suggest you check the grants
    if you need further pointers try a search for grant on this forum or check the MySQL help file for full details
    its something like

    Code:
    grant <permissions> on <table>.<database> to <user>.<hostname>  identified by <password>
    but remember to
    Code:
    Flush Privileges
    after the grant to make sure the server reloads the security privileges

  6. #6
    Join Date
    Oct 2003
    Posts
    706

    Smile

    It's very critical to check the MySQL logs as well as whatever your PHP program may produce.

    When you "go live" with your database, consider building error logging capabilities within your database layer that post the messages to a database table, then give a generic answer to the user. In this way, you can know what's going wrong, but they, if they have nefarious intentions, will not glean clues about what your database is doing from the error-messages they receive.

    Also: don't reinvent the wheel here. There are many well-developed PHP libraries and objects which are purpose-built for database access. Use them.
    Actum Ne Agas: Do not do a thing already done.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

  7. #7
    Join Date
    Oct 2003
    Posts
    232

    Arrow

    so how do i run the same thing with say SQl server run a select query and return the result as a web page so every time somebody clicks on the web page it updates itself


    say i want a query

    select * from autors (from pubs)
    bigfoots

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •