Database class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
z0
Forum Newbie
Posts: 15
Joined: Wed Sep 05, 2007 7:17 am

Database class

Post by z0 »

Hi :)
Anyone there to help me...
I get these two error messages when I run this code.They are:

Warning: mysqli::mysqli() [function.mysqli-mysqli]: (28000/1045): Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xxxxx\www\abc\xx\Database.class on line 16

Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in C:\xxxxx\www\abc\xx\Database.class on line 32
Database is not available. Try again later

Here is the code :-

Code: Select all

<?php

 require_once("PasswordPrompter.class");              #@@a10
 require_once("Database.class");
 require_once("Account.class");
 require_once("WebPage.class");

 //Testing whether the user has been prompted for a user name
 if(!isset($_SERVER['PHP_AUTH_USER']))                #@@a16
 {
    try
    {
       $prompter = new PasswordPrompter("secret section");
       $prompter->displayPrompt();
    }
    catch(Exception $e)
    {
       echo $e->getMessage();
       exit();
    }
 }

 // Testing the user name and password entered by the user
 else                                                 #@@a31
 {
    try                                               #@@a33
    {
       $db = new Database("Vars.inc");                #@@a35
       $db->useDatabase("UserAccount");               #@@a36
    }
    catch(Exception $e)
    {
       echo $e->getMessage();
       exit();
    }                                                 #@@a42
    try                                               #@@a43
    {
       $acct = new 
          Account($db->getConnection(),"Valid_User"); #@@a46
       if(!$acct->selectAccount($_SERVER['PHP_AUTH_USER']))
       {
          $mess = $acct->getMessage();
          echo $mess."<br>";
          exit();
       }                                              #@@a52
       if(!$acct->comparePassword($_SERVER['PHP_AUTH_PW']) )
       {
          $mess = $acct->getMessage();
          echo $mess."<br>";
          exit();
       }                                              #@@a58
    }
    catch(Exception $e)
    {
       echo $e->getMessage();
       exit();
    }
  }                                                   #@@a65
  $data['user_name'] = $_SERVER['PHP_AUTH_USER'];     #@@a66
  try                                                 #@@a67
  {
    $welcome_page = new WebPage("Welcome.inc",$data); #@@a69
    $welcome_page->displayPage();                     #@@a70
  }
  catch(Exception $e)
  {
    echo $e->getMessage();
    exit();
  }
?>
And,when I run this program,I get a login box asking for user name & password.When I supply the user name & password I get the above mentioned error messages !
I have already created a password list file,& created a "useraccount" database with a user & password.
Then why i am getting this error?
I should be getting a welcome page which I am not getting.

And my database.class file has this code in line 16 :-

if(!$this->cxn = new mysqli($host,$user,$passwd))

And,line 32 has this :-
if(!$result = $this->cxn->query("SHOW DATABASES"))


Regards,
Thanks
Last edited by z0 on Sun Sep 30, 2007 9:28 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

It's telling you that your database connection credentials are incorrect. You sure that the username is 'ODBC' and the password is empty? Oftentimes, the local database user name is 'root.'
z0
Forum Newbie
Posts: 15
Joined: Wed Sep 05, 2007 7:17 am

re:Database Class

Post by z0 »

Hi,
No,I am not sure what user name & password it is referring to!!
Actually,I am totally novice & don't have much knowledge of db programming.
I mean I don't know what ODBC means,also,not sure where is the username & password that is being referred is strored!!
I am using WAMP.And,my username is localhost /root (I'm not sure which one!!! :? )I have tried 'localhost' & 'mySQL password' but still getting that error!!
I have also tried 'root' & ' mysql 'password' but still no use.

Then I have also created a password list & a db 'useraccount'!!!
Also,can you please guide me, where the ODBC password is stored & how to change it?
Please,anyone there to give a complete step-by-step guide as to how to remove this error?

I will be greatly obliged.

Thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Your variables $user and $passwd should be 'root' and '' (that's an empty string), respectively, in order to connect to your local database.
z0
Forum Newbie
Posts: 15
Joined: Wed Sep 05, 2007 7:17 am

Database class

Post by z0 »

Your variables $user and $passwd should be 'root' and '' (that's an empty string), respectively, in order to connect to your local database.
What does that mean?
How is it related to the errors?
:roll:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Database class

Post by superdezign »

In database.class, where the connection is made.
Post Reply