Try fetch_array()
inplace of fetch_assoc()
fetch_array()
returns one array with both numeric keys, and associative strings (column names), so here you can either use $row['column_name']
or $row[0]
Where as fetch_assoc()
will return string indexed key array and no numeric array so you won't have an option here of using numeric keys like $row[0]
.
Change just below code -
php
$connection = new mysqli("localhost", "root", "");
$sql = "SHOW TABLES FROM MyDatabase";
$result = $connection->query($sql);
while ($row = $result->fetch_array()) {
echo "Table: {$row[0]}\n";
}
?>
manpreet
Best Answer
2 years ago
I've just started learning php.
I am trying to get a list of tables from my database. what I have tried -
But it does not show tables and returns -
Notice: Undefined offset: 0
. Any help?