SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation mysql connection issue

    Hey,
    I just bought the sitepoint book about PHP & MySQL by Kevin Yank And trying to set up a page that will connect to a mysql database and select data from a table.

    Here's some background info:
    I have MySQL and PHP running on Win2000 server (192.168.1.1) and telnet service running. I am able to connect to mysql via telnet from another machine on my network (btw, none of this is accessible through the firewall) I am not able to connect to mysql via a php string.

    I followed the steps in Ch. 4 verbatim, but I am getting this error:

    Unable to connect to the database server at this time.
    Access denied for user: 'root@MYCOMPUTERHOST.com' (Using password: YES)
    I put an echo in there to get what $dbcon was after it failed.

    I used this line:
    PHP Code:
    $dbcon mysql_connect("192.168.1.1""root""[mypasswd]"); 
    (I put my real password in between the parenthesis) Any ideas why it won't connect? When telnetting to the server and executing [mysqladmin.exe -u root reload] it errors and says the same error only listing 'No' instead of 'Yes'. When I -p for password and enter the right password I the command executes fine. So I know the password is functional.

    What's up with my code? Oh, here is the actual code in the page if that helps:
    PHP Code:
    <html>
    <title>View Blackbook</title>
    <body>
    <?php
    //Connect to database
    $dbcon = @mysql_connect("192.168.1.1" "root" "**mypass**");
    if (!
    $dbcon) {
       echo( 
    "<p>Unable to connect to the database server at this time.</p>" mysql_error() );
       exit();
    }
    echo(
    "$dbcon");
    // Select the blackbook database
    if (!@mysql_select_db("blackbook"$dbcon) ) {
       echo( 
    "<p>Unable to locate the Blackbook " "database at this time.</p>" );
       exit();
    }
    ?>

    <p> here is your listing</p>
    <blockquote>
    <?php
    // Request the text of members table
    $result=@mysql_query("select firstname, lastname, email, username, street1, city, state, zip, hphone from members");
    if (!
    $result) {
       echo(
    "<p>Error performing query: " mysql_error() . "</p>");
       exit();
    }

    // Display the address listings
    while ( $row mysql_fetch_array($result) ) {
       echo(
    "<p>" $row["firstname, lastname, email, username"] . "</p>");
    }
    ?>
    </blockquote>
    </body>
    </html>
    Any ideas? Also, why does the book put things like this in:

    PHP Code:
    echo( "<p>Unable to locate the Blackbook " "database at this time.</p>" ); 
    Why does it break in the middle of the sentence to '.' and then pick up again? I can see why if you were inserting a string in the echo, but this isn't the case here, is it?

  2. #2
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy selecting DB

    Ok,
    I think I have figured out the connection issue. I am now returning a '1' in $dbcon and no error message displays. The password thing was incorrect (though I don't know how it got that way!!)

    Now the next error is that it can not find the database I named in the sql command string. Everything is lowercase (though I don't think that matters unless you're using *nix-based installs)

    Again, I can telnet into mysql and can use [database]; and then show tables; without a problem. It's just when I try to do that using PHP.

    Any guru's wanna take a stab at this?

  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it looks fine to me. Just make sure your spelling is correct and yes, even in Windows, MySQL AND PHP are case-sensitive. They are both ports out of Unix and so the same rules apply.

    sKetch
    Aaron Brazell
    Technosailor



  4. #4
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down Looks fine... don't work tho

    Hey,
    I have triple checked all the syntax and case... I copied the dang thing straight out of the book and it don't work.

    Just for kicks, I downloaded the code-archive from sitepoint and used the exact same jokes.php script only modifying the host, user, pass and db sections. Same problems.

    Now that I am able to connect (or so I think) to the database, it still can not locate the database... hmmm.

    I have seen other PHP scripts that use the 'OR DIE("msg"); on the end of a line. Is this the ultra short version of the if the command returns false, to stop the script and display the error?

    As you might assume, I am a newbie in PHP and MySQL. If the script right out of the book don't work... what's a guy to do!?

  5. #5
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,811
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Take out the "@'s" and see what message you get....
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  6. #6
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Nope didn't help

    I took out the '@'s and still had the unknown database error. It's weird because I know the database is there, and I know I spelled it right.

    This doesn't seem that hard. I understand what the book is saying and I have coded right.

    Has anyone here gone through the Sitepoint book on PHP and MySQL chapter 4 and setup the jokes database and tried to make these pages? Did they work? What setup did you use for PHP and MySQL (I am using the latest stable distros on win2K Server)

    I hate to sound like I am begging (very unbecoming) but someone smarter than me has to know what the f**k I am doing wrong

    Try the page yourself

    The code is listed previously in this thread.


Bookmarks

Posting Permissions

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