list all tables in a database with MySQLi

后端 未结 4 1795
梦谈多话
梦谈多话 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条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 04:52

    here is little example

    class database {
        public $connection;
    
        function __construct() {
            $this->connection = mysqli_connect(DBHOST,
                                               DBUSER,
                                               DBPASS,
                                               DBNAME) or 
            die('Database Connection Error: '.mysqli_connect_error());  
        }
    
        public function close_database() { 
            return mysqli_close($this->connection); 
        }
        public function query($query) {
            $query = mysqli_query($this->connection ,$query) or die($this->show_errors('Query Execution Error: '.mysqli_error($this->connection),'E'));
            return $query;  
        }
        public function fetch_assoc($query) {
            $query = mysqli_fetch_assoc($query);
            return $query;  
        }
    }
    
    $db = new database();
    $query = $db->query("SHOW TABLES FROM DATABASENAME");
    $db->fetch_assoc($query);
    

提交回复
热议问题