我正在尝试根据用户输入(不同查询所需的不同表)从数据库中获取表名。我有以下代码:
function getTables(){
$dbConn = new dbConn();
$conn = $dbConn->connect();
$data = $conn->query('SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = "dbName" AND table_name LIKE "' . $this->table . '%";');
$tables = $data->fetchALL(PDO::FETCH_ASSOC);
foreach($tables as $item) {
echo $item;
}
return $tables;
}
上面的输出是ArrayArrayArrayArray,这让我相信我正在处理数组数组。当我print_r($ tables)时,我得到:
Array ( [0] => Array ([table_name] => my_table0) [1] => Array ([table_name] => my_table1) etc. etc.
如何从查询中获取实际的表名?