php – PDO SHOW TABLES数组

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – PDO SHOW TABLES数组脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
只是使用这个功能,它没有按计划进行.它应该抓取数据库中的所有表名并将它们存储在一个数组中.但是,数组的结果使下面示例中显示的数组加倍:
Array ( [0] => 113340 ) 
Array ( [0] => 113340 [1] => 116516 ) 
Array ( [0] => 113340 [1] => 116516 [2] => 139431 ) 
Array ( [0] => 113340 [1] => 116516 [2] => 139431 [3] => 20731 ) 
Array ( [0] => 113340 [1] => 116516 [2] => 139431 [3] => 20731 ... )

我正在使用的代码

function ITemDiscontinued($dbh,$id,$detail) {
  try {
    $tableList = array();
    $result = $dbh->query("SHOW TABLES");
    while ($row = $result->fetch(PDO::FETCH_NUM)) {
      $tableList[] = $row[0];
      PRint_r($tableList);
    }
  }
  catch (PDOException $e) {
    echo $e->getMessage();
  }
}
得到表的所有名称这要好得多
public function list_tables()
{
    $sql = 'SHOW TABLES';
    if($this->is_connected)
    {
        $query = $this->pdo->query($sql);
        return $query->fetchAll(PDO::FETCH_COLUMN);
    }
    return FALSE;
}

脚本宝典总结

以上是脚本宝典为你收集整理的php – PDO SHOW TABLES数组全部内容,希望文章能够帮你解决php – PDO SHOW TABLES数组所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。