只是使用这个功能,它没有按计划进行.它应该抓取数据库中的所有表名并将它们存储在一个数组中.但是,数组的结果使下面示例中显示的数组加倍:
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;
}