Page 1 of 1

Access denied for user 'ODBC'@'localhost' in sub folder

PostPosted: 02. January 2008 15:18
by qwe010
hello

i have problem with all my scripts

in the first folder

127.0.0.1/myscript

works good

but in sub folder

127.0.0.1/myscript/admin

i see

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


what user ODBC !!!!

PostPosted: 02. January 2008 15:30
by Wiedmann
The MySQL configuration for your script is wrong.

PostPosted: 02. January 2008 16:57
by qwe010
no it's works good

but the problem just in sub folder

but in ( vbulliten ) works good ?

the MySQL configuration

like other


$dbhost = "localhost";

$dbuname = "root";

$dbpass = "";

$dbname = "myscript";


in vbulliten

$dbhost = "localhost";

$dbuname = "root";

$dbpass = "";

$dbname = "vb";

PostPosted: 03. January 2008 16:29
by KallistaAEnvarou
I'm guessing that ODBC is a standard, mysql-used user to do queries and such. If your server connection failed, then you won't be able to do any sql functions, and you'll retrieve this error. The only way to know why it failed to use an "or die" statement with your connection.

Example:
mysql_connect($host,$user,$password) or die('Could not connect: ' . mysql_error());

For your case, it's much better to use the built-define function as define('SERVER','localhost') define('DBUSER',$username), etc. and type mysql_connect(SERVER,DBUSER,$db) instead of $server='localhost', because, if you use variables, you have to be careful about connecting inside functions since those variables don't pass along automatically. OR, you can create a function to make sure that you automatically sign in to a given user in a given database, such as with this function:

Code: Select all
function con($user,$database,$line)
{
   /**
   Function statement: connects to a database on localhost using a given user and database, and errors with a unique, descriptive method if no connection is possible
   Input
      $user:
         parameter passed to the function
         describes which user is supposed to connect to the server
      $database:
         parameter passed to the function
         describes which database $user is supposed to select
      $line
         parameter passed to the function with __LINE__
         describes the line which produced an error when an error occurs
      $file:
         variable brought in using the global keyword
         defined in the file to point to which file where any error occurred
   Process
         $GLOBALS['con']=@mysql_connect(localhost', $user,'Char1133') or die("Connection of $user on $line in $file failed: " . mysql_error()); //$GLOBALS['con'] allows the $con variable to be used in the originating file after the function has processed; the @ suppresses any warnings
         $GLOBALS['db']=@mysql_select_db($database) or die("Selection of $database on $line in $file failed: " . mysql_error()); //$GLOBALS['db'] allows the $db variable to be used in the originating file after the function has processed; the @ suppresses any warnings
   Output
      $GLOBALS['con'], passed as $con to the file, to return the connection on success
      $GLOBALS['db'], passed as $db tot he file, to return the database selection upon success
      Error message returned on failure, and the script exits
   */
   
   $GLOBALS['con']=@mysql_connect('localhost', $user,'password_goes_here') or die("Connection of $user on $line in $file failed: " . mysql_error());
   $GLOBALS['db']=@mysql_select_db($database) or die("Selection of $database on $line in $file failed: " . mysql_error());
}


Then, whenever you need to connect, inside a function or elsewhere, all you need to do is type something like:

$file='filename.php'
con('root','mydatabase');

and you're done. If there are any problems, then you will know exactly what it is.

Note: If you have varying passwords for different users, or if you have only one user, or if you only have one database, add or subtract parameters as necessary.