getting error...help please

Discussion in 'MySQL' started by deemainer, Mar 4, 2009.

  1. #1
    Hi all

    Getting into sql and making progress.Trying to write php query but getting this message

    Access denied for user 'apache'@'localhost' (using password: NO)

    heres the code ive got to:


    // username
    $dbuser="blah blah";
    // password
    $dbpass="blah blah";
    // db name
    $dbname="blah blah";

    $chandle = mysql_connect("localhost", $dbuser, $dbpass)
    or die("Connection Failure to Database");
    echo "Connected to database server....<br>";
    mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found." . $dbuser);
    echo "Database " . $database . " is selected";
    mysql_close($chandle);

    $sql = 'SELECT * FROM `PLD_LINK` WHERE `STATUS` = 1 LIMIT 0, 30 ';
    if ($result=mysql_query($sql)) {
    if ($row=mysql_fetch_row($result)) {
    echo "Column 1 is ".$row[0]."<br>\n";
    echo "Column 2 is ".$row[1]."<br>\n";
    }
    } else {
    echo "<!-- SQL Error ".mysql_error()." -->";
    }?>


    heres the response i get:

    Connected to database server....
    Database is selected

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'@'localhost' (using password: NO) in /home/domains/mydomain/www_root/connect.php on line 19

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/domains/mydomain/www_root/connect.php on line 19



    Any ideas??? The initial connection seems to be made ok...so i dont know.

    Thanks in advance
     
    deemainer, Mar 4, 2009 IP
  2. byyp

    byyp Active Member

    Messages:
    614
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You are unable to reach your database due to either the username,database name or password being incorrect.

    Your connect.php file must have a command to reach the database, but is unable to do so because of the above said error, and thus is returning the error. Please re-check your info.
     
    byyp, Mar 4, 2009 IP
  3. kailash

    kailash Well-Known Member

    Messages:
    1,248
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    190
    #3
    Make sure the database user which you have specified in the script has permissions to access database. Also make sure you have enter correct username and password.

    Kailash
     
    kailash, Mar 4, 2009 IP
  4. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #4
    how this file is called? is thiscode from connect.php?
     
    crivion, Mar 5, 2009 IP
  5. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #5
    Yes...this is connect php. Im calling connect.php in browser.

    I think its connecting fine. I get this reply when i launch in browser:

    So the first two lines tell me im connected to db ok...but its the next bit im stumped by. Ive cobbled the code from two tutorials.
     
    deemainer, Mar 5, 2009 IP
  6. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #6
    AAAh ! worked it out thanks.

    mysql_close($chandle);

    was closing db connection before next code.

    Thanks all.
     
    deemainer, Mar 5, 2009 IP
  7. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #7
    huh lol, what a terrible mistake, no one of us could see it lol
     
    crivion, Mar 5, 2009 IP
  8. deemainer

    deemainer Active Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #8
    I know !! DOH ! Im a SQL noob though so i have an excuse :)
     
    deemainer, Mar 5, 2009 IP