Submit Your Article Forum Rules

Results 1 to 3 of 3

Thread: mysql_connect.. no connection and no error

  1. #1
    Senior Member ristenk1's Avatar
    Join Date
    Apr 2009
    Posts
    122

    mysql_connect.. no connection and no error

    This seems like it should be so easy but I am not getting an error or any result:

    $connection = mysql_connect("phpexamplesite.db.4211592.hostedres ource.com", "username", "password");
    if(!$connection) {

    die("Database connection failed: " . mysql_error());
    }


    //2. Select a database to use


    $db_select = mysql_select_db("username", $connection);
    if(!$db_select){
    die("Database selection failed: " . mysql_error());

    Any ideas?

    THanks

    ---------- Post added at 10:50 AM ---------- Previous post was at 10:42 AM ----------

    I think the error is in the connection but here is the rest of it:
    // 3. Perform database query
    $result = mysql_query("SELECT * FROM subjects", $connection);
    if(!$result){
    die("Database query failed: " . mysql_error());
    }

    //4. Use returned data

    while($row = mysql_fetch_array($result)) {
    echo $row["menu_name"]. " ".$row["position"]. "<br />";
    }

    ?>

    <?php
    //5. Close connection

    mysql_close($connection);

    ?>
    I'm not getting any error or results on the page...

  2. #2
    Senior Member NetProwler's Avatar
    Join Date
    Jan 2007
    Posts
    197
    Actually the server will crib loudly - only thing is its crib will be in the error_log. Set the PHP to show errors like this at the beginning of your script:
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    The above will turn on reporting of errors on the browser.

  3. #3
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    And also note that you might be getting error messages in the returned HTML but if they're not in a displayable part of the code you won't see them on the browser screen. Make sure you look at the source of the page in your browser.
    Dynamic Software Development
    www.activeminds.ca

Posting Permissions

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