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
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.
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
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.
AAAh ! worked it out thanks. mysql_close($chandle); was closing db connection before next code. Thanks all.