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

  • SEARCH
  • Home
  • 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 7189497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:18:54+00:00 2026-05-28T19:18:54+00:00

I have reproduced this function: function getTables() { global $db; $value = array(); if

  • 0

I have reproduced this function:

function getTables()
  {
      global $db;

      $value = array();
      if (!($result = $db->query('SHOW TABLES'))) {
          return false;
      }
      while ($row = $db->fetchrow($result)) {
          if (empty($this->tables) or in_array($row[0], $this->tables)) {
              $value[] = $row[0];
          }
      }
      if (!sizeof($value)) {
          $db->error("No tables found in database");
          return false;
      }
      return $value;
  }

in this manner:

public function getTables() {

    $value = array();

    $tables = array();

    $sql = "SHOW TABLES";

    if($stmt = $this->connect->prepare($sql)) {
        $stmt->execute(); 
        while( $row = $stmt->fetch_row() ) {        
            if(empty($tables) or in_array($row[0], $tables)) {
                $value[0] = $row[0];
            }       
        }

        $stmt->close();

        if(!sizeof($value)) {
            echo 'The database has no tables';
        }

        return $value;

    } else {

        echo 'Couldn\t query the database';

    }

}

But the second method returns me The database has no tables which is not true because I have one table in the db.

What is it wrong with the second method ?

In case you wonder what connect does :

public $connect;
public function __construct() {
    // Define The Database Connection Or Die If Failed Connecting
    $this->connect = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die(DB_CONNECTION_ERROR_MESSAGE);
}

It make a connection with the database. And prepare() it’s a mysqli statement. I tried with query() too, same result.

  • 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-28T19:18:56+00:00Added an answer on May 28, 2026 at 7:18 pm

    Correct code. Use query instead of prepare:

    public function getTables()
    {
        $value = array();
        $tables = array();
    
        $sql = "SHOW TABLES";
    
        if ($res = $this->connect->query($sql))
        {
            while ($row = $res->fetch_row())
            {
                if (empty($tables) or in_array($row[0], $tables))
                {
                    $value[] = $row[0];
                }
            }
    
            if (!sizeof($value))
            {
                echo 'The database has no tables';
            }
    
            return $value;
        }
        else
        {
            echo 'Could not query the database';
        }
    }
    

    If you still want to use prepare then you will also need $stmt->bind_result and $stmt->fetch() instead of fetch_row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across this issue in my application, and have reproduced it using Apple's
I have this jQuery code: <script type=text/javascript> $(document).ready(function() { $('.vote_up').click(function() { alert ( test:
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
The project is ASP.NET 2.0, I have never been able to reproduce this myself,
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I'm developing an Eclipse plug-in and I have a problem which is reproduced here:
I am using SQL Server 2008. I have a query that pulls two random
I have some FLV video files to be reproduced sequentially by a Flash video
I have a paragraph, which I would like to edit using javascript prompt function.
Based on this original idea, that many of you have probably seen before: http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/

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.