SitePoint Sponsor

User Tag List

Results 1 to 20 of 20

Hybrid View

  1. #1
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unable to locate db...??

    Hi,
    I have been using phpmyadmin to mess around with my database (I'm at chapter 4 of Kevin Yanks db book...)

    I have successfully connected to the MySQL server;

    PHP Code:
    <?php 
    // Connect to the database server
    $dbcnx = @mysql_connect('207.44.142.94''root''******');
    if (!
    dbcnx
    {
    echo( 
    '<p>Unable to connect to the ' .
    'database server at this time.</p>' );
    }
    else
    {
    echo( 
    'connected!!' );
    exit();
    }
    ?>
    I then ran this, to locate my db...
    PHP Code:
    <?php 
    // Connect to the database server
    $dbcnx = @mysql_connect('207.44.142.94''root''******');
    if (!
    dbcnx
    {
    die( 
    '<p>Unable to connect to the ' .
    'database server at this time.</p>' );
    }
    // Select the database
    if (! @mysql_select_db('nedesign') )
    {
    die( 
    '<p>Unable to locate the nedesign ' .
    'database at this time.</p>' );
    }
    ?>
    <p>Here are all the jokes in the database: </p>
    <blockquote>
    <?php
    // Request the text in all the jokes
    $result = @mysql_query('SELECT joketext FROM jokes');
    if (!
    $result)
    {
    die(
    '<p>Error performing query: ' mysql_error() . 
    '</p>');
    }
    // Display the text of each joke in paragraph
    while ( $row mysql_fetch_array($result) )
    {
    echo(
    '<p>'$row['joketext'] . '</p>');
    }
    ?>
    It returns;
    'Unable to locate the nedesign database at this time'

    Though, as I mentioned - I've been using the nedesign db - I added a jokes table using phpmyadmin...??

    Very confusedly yours,
    Nick

  2. #2
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you miising your database selection line?

    Code:
     // Select the database 
     
     //missing this line to select your database before checking the connection
     
      mysql_select_db('nedesign',$dbcnx);
     
     //back to your script
     
     
     if (! @mysql_select_db('nedesign') ) 
    { 
    die( '<p>Unable to locate the nedesign ' . 
    'database at this time.</p>' ); 
    } 

  3. #3
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope - that's there....

    Funny though, I read a thread where someone was having the same prob...
    They finished by saying- Ahh Ha! I've got it - I took out the the '!' and now it has located my db... I got all excited when that worked for me too...

    But then I realised that the '!' is the negation operator...

    Perhaps my problem is more fundamental...
    I've been conentrating about as hard as I can as I work through Kevin Yanks book - but when you're new to all of this, understanding the relationships between php scripts, mysql servers, sql's, phpmyadmin, winmysqladmin, telnet, ssh, command prompts etc... well... it can be hard to grasp.

    As I mentioned in my initial post, I've been modifying my database with phpmyadmin - and I've connected to the mysql server with the php script above.
    Is there something else I'm supposed to have running in the background, that you may have assumed I knew to do...?? Anything that may seem obvious to you, could very well not be to me

    Thanks for any suggestions!!

  4. #4
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you testing your script on your own machine? or do you have a host?

  5. #5
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I'm using my hosts MySQL server...
    I'm uploading my php scripts each time to see if I can access the db my host has provided me.

  6. #6
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK

    Has your host given you a database user name? If they have then you should use this instead of 'root' in your connection string.

    Also, (although you should be able to see this in PHPMyAdmin) make sure that your host doesn't prefix your database with anything (some add your username like username_nedesign).

    And finally, location Sydney !?! Shouldn't you be asleep?!?

  7. #7
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sleep - Ke?

    They've just given me the IP address and my login name and password - which is the same as my FTP...

  8. #8
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, and my database appears to be referred to as just 'nedesign'...

  9. #9
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK
    so change your connection string to show these

    Code:
    $dbcnx = @mysql_connect('207.44.142.94', 'ftpusername', 'ftppassword');


    Any better?

  10. #10
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's what I'm using...
    ?

  11. #11
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, sorry - I was using root, but i did try that aswell...
    and no luck!

  12. #12
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Though, I just managed to connect with nedesign instead of root... ???
    Did I need to set up another password to view the database..?
    I've got nothin'

  13. #13
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you are actually connectingf to the mysql server in the first script you posted?

    I only ask because the error check you have in there looks wrong.

    Code:
    if (!dbcnx)

    should be
    Code:
    if (!$dbcnx)


    If that is connecting and your database name is correct then you may be better speaking to your host and see if there is something else missing.

  14. #14
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bugger!
    So, I'm not connecting...
    Though atleast that answers my question of not being able to locate the db...
    Any suggestions as to what I should do now in order to connect...

  15. #15
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well at least we're not both going mad

    Is the IP address correct?

    You can try using localhost instead. (it depends if the Mysql database is on the same server or not)

    Here is the connection string I use on my sites.

    Code:
    <?php
     
     $dbh=mysql_connect ("localhost", "myftpusername", "myftppassword") or die ('I cannot connect to the database because: ' . mysql_error());
     mysql_select_db ("jokelist"); 
     
     ?>

  16. #16
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yaaaaay!!
    Thank you!!
    localhost it was - I could have sworn I'd tried that, though I must have been using 'root'...

    I'll quickly try to locate my db...

  17. #17
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, I can't tell you how much I appreciate your help!!

    It says it's located my db... but just to be sure can you check this code for me..
    PHP Code:
    <?php
    $dbcnx 
    = @mysql_connect('localhost''nedesign''*******');
    if ( @
    mysql_select_db('nedesign') ) {
    echo( 
    '<p>located nedesign...</p>' );
    } else {
    echo(
    '<p>nedesign not found!!!</p>' );
    }
    ?>
    2am.... - maybe sleep's a good idea!!

  18. #18
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks good to me.

    Stick in your original script and see if you get any results. that's when the real fun starts

  19. #19
    SitePoint Enthusiast rexoids's Avatar
    Join Date
    May 2004
    Location
    Sydney
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tomorrow, tomorrow, I love you tomorrow - your only a... oh, it is tormorrow...
    Thanks again!

  20. #20
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No Problem

    Good luck and get some sleep. Me, I'm just leaving work


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
  •