php - PDO SHOW TABLES array -
just working function , it's not working out planned. supposed grab table names in database , store them in array. results of array doubling array shown in example below:
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 ... )
the code using:
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(); } }
to names of tables better
public function list_tables() { $sql = 'show tables'; if($this->is_connected) { $query = $this->pdo->query($sql); return $query->fetchall(pdo::fetch_column); } return false; }