SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a few simple lines of code to connect to a database from my web page, (code based on Kyank's tutorials). The code runs as follows:

    <?php

    // Connect to the database server
    $dbcnx = @mysql_connect("localhost","-----", "-----");
    if (!$dbcnx) {
    echo( "<br>Unable to connect to the " .
    "database server at this time." );
    exit();
    }
    else echo ("Server connect... ok.");


    // Select the projects database
    $dbsel = @mysql_select_db("projects");
    if (!$dbsel) {
    echo( "<br>Unable to locate the project " .
    "database at this time." );
    exit();
    }
    else echo ("<br>Database connect... ok.");

    ?>

    I get the "Server connect ok" line, but always receive the "unable to connect to projects database" line after.
    I have double-checked the name of the database, the location certainly is correct, and I've even been able to modify the db with phpMyAdmin even when this code says the db is unavailable. Thus, I figure my code is buggy somehow, but I just can't see it.
    Help, anyone? Thanx


    ------------------
    mp
    www.honeyb.com

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know why this posted twice... sorry vinay / kyank.

  3. #3
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace the line:
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    $dbsel = @mysql_select_db("projects");
    [/code]
    to
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    $dbsel = @mysql_select_db("projects", $dbcnx);
    [/code]

    ------------------
    Karl Austin
    KDA Web Services
    "Everyone has a photographic memory. Some just don't have film."

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The parameter that Karl suggests adding is optional, and should not be needed.

    I can't see anything wrong with the code. Are you positive you've got the name of the database right down to the case (e.g. "Projects" instead of "projects")?


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  5. #5
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>I can't see anything wrong with the code.<HR></BLOCKQUOTE>

    You are right. I tried the code to access my own database and it worked fine.

    ------------------
    Antti
    Huotari.com/antti/
    LinuxWebDevNews.com

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HA HA HA!!! total newbie mistake. "projects" is actually the name of a table within my database, not the database name itself. i fixed the call and now connect just fine. now all i have to do is figure how to work with the tables within a DB. :P
    thanx all for your help.


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
  •