list all tables in a database with MySQLi

后端 未结 4 1798
梦谈多话
梦谈多话 2021-02-14 04:13

I have looked around and still can\'t find how to list all my tables in a database. is it possible with MySQLi?

Thanks.

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 04:43

    I'd try something like:

    function get_tables()
    {
      $tableList = array();
      $res = mysqli_query($this->conn,"SHOW TABLES");
      while($cRow = mysqli_fetch_array($res))
      {
        $tableList[] = $cRow[0];
      }
      return $tableList;
    }
    

    You might also be interested in skimming this: https://devzone.zend.com/13/php-101-part-8-databases-and-other-animals_part-2/ (EDIT: this link refers to mysql API and not mysqli, but most calls do have a mysqli parallel).

    HTH

提交回复
热议问题