Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6658863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:47+00:00 2026-05-26T01:57:47+00:00

This is my first time here so i hope you can help me. This

  • 0

This is my first time here so i hope you can help me. This is my problem:

I’m busy with a log-in script in oop.

I have the following classes ready:

  • database class
    this is just an connection/disconnection class

  • query class extends the database class
    there is only 1 function and that only takes a query string and get it through the database and eventually returns an array with the data.

  • login class
    this class will get user login information and gets user informatie from the database.

this is the folder structure:

/
/cgi-bin -> holds the database and query class
/libraries -> holds the login class

Then there are 2 files left and they are the index.php and the global.php.

In my index I have this:

require_once('global.php');

print_r($login->userCheck('test'));

and this is inside my global.php:

include('cgi-bin/database.php');
include('cgi-bin/query.php');
include('libraries/login.lib.php');


$login = new Login();

this is my login class

class Login extends Query{

  public function Login(){

  }

  public function userCheck($userCredentials){
  $result = $this->qString('SELECT * FROM users');
  return $result;

}

}

and my query class

class Query extends Database{
  function qString($qString){

    //Start connection with database
    $this->conncect();

    $result = $this->db->query($qString);
    // fetch associative array
    while ($row = mysqli_fetch_assoc($result)) {
      $data[] = $row;
    }

    // free result set 
    mysqli_free_result($result);

    //Close connection with database
    $this->disconnect();

    //Check mysqli connection
    //print_r(explode('  ', mysqli_stat($this->db)));

    return $data; 

  }
}

and the database class:

class Database {

  //Private variables for database connection.
  private $server;
  private $usern;
  private $userp;
  private $database;

  //The database object.
  protected $db;

  function Database(){

    $dbCredentials = explode(',',file_get_contents('cgi-bin/dbcredentials.txt'));

    $this->server = $dbCredentials[0];
    $this->usern  = $dbCredentials[1];
    $this->userp  = $dbCredentials[2];
    $this->db     = $dbCredentials[3];

  }

  protected function conncect(){            
    $this->db = mysqli_connect($this->server, $this->usern, $this->userp, $this->db);
  }

  protected function disconnect(){
    mysqli_close($this->db);
  }

}   

now when I run this it says this:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Login\cgi-bin\query.php on line 11

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Login\cgi-bin\query.php on line 16

Notice: Undefined variable: data in C:\xampp\htdocs\Login\cgi-bin\query.php on line 25

Why am I getting this error?

Edit 12-10-2011:

I have found what the error was.

just to share it with you:
There error was that the construct from the database class was never run.

Because of that, the connection details like username and password were never set to the private variables and with that it could never connect.

With the result that the query never could run from the login class.

So it was pretty simple in the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:57:47+00:00Added an answer on May 26, 2026 at 1:57 am

    You need to read the documentation for mysqli::query. It returns a result set only when there are results. On error, it will return boolean false, and for many types of queries it will return a boolean true on success:

    Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a MySQLi_Result object. For other successful queries mysqli_query() will return TRUE.

    You’re also not checking the return value of $this->db->query(...). If it is failing and returning false, you’re blindly passing that boolean value to mysqli_fetch_assoc, hence the error message

    mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
    

    Please add some basic error handling to your code:

    $result = $this->db->query($qString);
    
    if ($result === false) {
      // error in query
      die("'$query' failed");
    }
    
    if ($result === true) {
      // not a query which returns results
      return true;
    }
    
    // fetch associative array
    while ($row = mysqli_fetch_assoc($result)) {
      $data[] = $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time posting my problem here, i hope i get help
this is my first time to post here. I have a problem on my
I have a big problem I hope some one can help me with it.
I hope you can help me with a problem; first, please don't worry about
this is my first time asking a question here so I hope I am
That is my first topic here.i hope you can help me. I don't know
This is my first time with Web services. I have to develop web services
I have recently started learning F#, and this is the first time I've ever
So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse
hope you can help me! I have a form, which has a large amount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.