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 8538651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:10:13+00:00 2026-06-11T11:10:13+00:00

I am making a PHP function to return an array of a mysql database’s

  • 0

I am making a PHP function to return an array of a mysql database’s table’s info. I am new to coding in php and am looking for more efficient way to do the same thing I have done because my method does not seem very efficient. Would this be a good place to use a mysql join statement?

Here is my function.

public static function getAllTables()
{
    // Get an array of all the tables in the database
    $sql = "SHOW TABLES";

    //this makes a connection to mysql database using mysqli
    $mysqlConnection = new CMySqlConnection(); 
    $result = $mysqlConnection->mysqli->query($sql);
    $tablesArray = array();
    while($row = $result->fetch_row()) {

        $tablesArray[$row[0]]=array();

    }

    $result->close();

    //Get an array of all the table names in database
    $arrayKeys = array_keys($tablesArray);

    //foreach table get the column's info
    foreach($arrayKeys as $key){ 
        $sql="  SHOW COLUMNS from " . $key;
        $result = $mysqlConnection->mysqli->query($sql);
        for($i = 0; $row = $result->fetch_row(); $i++) {

            //format the array to use a descriptive key rather than a number
            $row['columnName'] = $row[0];
            $row['type'] = $row[1];
            $row['null'] = $row[2];
            $row['key'] = $row[3];
            $row['default'] = $row[4];
            $row['extra'] = $row[5];

            unset($row[0]);
            unset($row[1]);
            unset($row[2]);
            unset($row[3]);
            unset($row[4]);
            unset($row[5]);

            // put the column info into the tables array
            $tablesArray[$key][$i] = $row;
        }
        $result->close();
    }


    $mysqlConnection->Disconnect();

    // return the tables array
    return $tablesArray;
}

Thanks for any input 🙂

  • 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-06-11T11:10:15+00:00Added an answer on June 11, 2026 at 11:10 am

    You can just query the INFORMATION_SCHEMA. They are virtual tables which contain information about your database: http://dev.mysql.com/doc/refman/5.5/en/information-schema.html

    SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
    
    SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='schema' AND TABLE_NAME='table';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a PHP function that converts a $_GET array into the URL string
<?php function convertDates($timestamp) { return date('Y-d-m', $timestamp); } $days = array(); //store all the
I use JEditable for making edit field which following code: $(function() { $(.field).editable(http://localhost/index.php/welcome/update_record, {
So today, I'm finally making the transition from standard PHP MySQL functions to PDO.
I am making a function (PHP). In this function it basically uses the dbms
I have thought a bit about making a somewhat lightweight consistent-hashing-like PHP function to
PHP mysql database I have created a follow on question to this one here
I am making an ajax call in jquery $.get(validate_isbn.php, {isbn: obj[16]}, function(answer) { console.log(answer);
I need some help regarding making a form using PHP, MySQL, and jQuery. Here
Does making php 4.4.9 ./configure --with-openssl is necesary to enable ssl, cause when i

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.