Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将给定数据库的所有数据表名称放入一个数组中_Php - Fatal编程技术网

Php 将给定数据库的所有数据表名称放入一个数组中

Php 将给定数据库的所有数据表名称放入一个数组中,php,Php,如何在连接到mysql数据库后仅获取数据选项卡名称 $query = $db1->prepare('show tables'); $query->execute(); $Columns = array(); $index = 0; while($rows = $result->fetch(PDO::FETCH_ASSOC)){ var_dump($rows); $Columns[$index] = $ro

如何在连接到mysql数据库后仅获取数据选项卡名称

$query = $db1->prepare('show tables');
    $query->execute();
     $Columns = array();
     $index = 0;
     while($rows = $result->fetch(PDO::FETCH_ASSOC)){
         var_dump($rows);
         $Columns[$index] = $row;
         $index++;
                 }
我想获得如下列表:[表1,表2…] 但第6行的结果是:

array(1) { ["Tables_in_database_name"]=> string(5) "tabel1" } array(1) { ["Tables_in_database_name"]=> string(10) "Datacamera" } array(1) { ["Tables_in_datacam"]=> string(7) "......." } }

可以添加哪些php命令来仅提取数据表名称?

尝试将
PDO::FETCH_ASSOC
更改为
PDO::FETCH_NUM

请试一试

$query = $db1->prepare('show tables');
$query->execute();
 $Columns = array();
 while($row = $result->fetch(PDO::FETCH_NUM)){
     $Columns[] = $row[0];
 }

如果您使用的是MySQL,那么您可以使用以下查询从information_schema数据库中获得这一结果集:-

select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='YOUR_DATABASE_NAME_HERE';

您可能需要为您的应用程序授予用户选择访问信息模式数据库的权限。

解析该数组很容易,只留下所需的值。我知道我必须解析数组以过滤它并获得所需的值,但我不知道它如何显示:数组(1){[0]=>string(6)“xxxxxx”}数组(1){[0]=>string(10)“xxxxxxxxx”}数组(1){[0]=>string(7)“xxxxxxx”}和xxx是数据表名称输出是:string(6)“xxxxxx”string(10)“xxxxxxxxx”string(7)“xxxxxxx”我尝试了$row[0][0],但它只显示每个数据表名称字符串(1)“x”string(1)“x”string(1)“x”string(1)“xuse
$row[0]
请回答上面的问题。
$query = $db1->prepare('show tables');
    $query->execute();
     $Columns = array();
     $index = 0;
     while($rows = $result->fetch(PDO::FETCH_ASSOC)){
         var_dump($rows);
         $Columns[$index] = $row;
         $index++;
                 }