clown[NOR] Posted April 13, 2007 Share Posted April 13, 2007 i have been fighting this problem for a while now, but with no luck.. i just cant see why it wont work... it might be the function... it's the first time i'm working with it... so.. this is the error message i get: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in F:\root\oleaa.com\index.php on line 21 Unable to connect to DB this is the code: <?php include('config/db.php'); function freshNews() { if (!mysql_connect($dbHost, $dbUser, $dbPass)) { die("Unable to connect to DB"); } //This is line 21 if (!mysql_select_db($dbName)) { die("Unable to select DB"); } $query = "SELECT * FROM news"; $result = mysql_query($query); if (!$result) { die("Could not run query from DB"); } $dbNumRows = mysql_num_rows($result); if ($dbNumRows > 0) { echo $dbNumRows . " news found."; } else { echo "No news found."; } } Thanks In Advance - Clown Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Author Share Posted April 13, 2007 ok.. i figured it out... i had to move the include() inside the function... but... is there a way so I dont have to do that? Quote Link to comment Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 not sure why it needs to be in the function for that... shouldnt need to be... but if you include_once(); you can put it in either/both spots... problem solved :-) Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Author Share Posted April 13, 2007 hehe... oh well... i tried to add it as include_once() outside the function ... didnt work.. if that's what you ment tho... oh well.. it's jsut the db.php... so it's ok... but if anyone have an solution for this.. please let me know... Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 http://us2.php.net/manual/en/language.variables.scope.php Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Author Share Posted April 13, 2007 this is the db file.. tried to make the variables global... but it didn't work <?php global $dbHost, $dbUser, $dbPass, $dbName; $dbHost = "localhost"; $dbUser = "root"; $dbPass = ""; $dbName = "oleaa"; ?> Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 put global $dbHost, $dbUser, $dbPass, $dbName; in your function before you use the variables Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 13, 2007 Author Share Posted April 13, 2007 aaahhh... *feeling stupid* haha... thanks m8 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.