SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2000
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I am currently studying the php tutorial and am having connection problems:

    My webhost provides mySQL which I acess via telnet. I wish simply to access my database using the following php commands:


    <?php
    // Connect to the database server
    $dbcnx = @mysql_connect("localhost", "root", "mypasswd"); if (!$dbcnx) {
    echo( "<P>Unable to connect to the " .
    "database server at this time.</P>" );
    exit(); }
    // Select the "mydatabase" database
    if (! @mysql_select_db("mydatabase") ) {
    echo( "<P>Unable to locate the database " .
    "database at this time.</P>" );
    exit(); }
    ?>

    I have tried a number of variations to connect (localhost, IP addresses etc) to access mySQL database without success. I have also tried entering false passwords and usernames to verify the error script.

    When connecting to mySQL via telnet I use a username and password firstly to access telnet then another username,pswd to access mySQL.

    Any suggestions?

    Sp.

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide us with the error your are getting? That usually helps a great deal.

  3. #3
    SitePoint Member
    Join Date
    Jan 2000
    Location
    North Bend, Oregon USA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works for me. I usually define the variables in a require file, but for simplicity...

    Don't know if this helps. It should get you connected and then you can experiment with making the connection string a variable, adding error checking, etc.

    <?php
    $host='localhost' ;
    $user='username' ;
    $pass='passwd' ;
    $dbname='dbname' ;

    mysql_connect ($host, $user, $pass);
    mysql_select_db ($dbname);
    ?>
    Dan


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
  •