$db = mysqli_connect('localhost', 'user', 'password', 'database'); $rows = $db->getSchema()->getTable('table_name')->getColumns(); foreach($rows as $row) { echo $row->getName() . "\n"; }
$db = new PDO("mysql:host=localhost;dbname=database", "user", "password"); $schema = $db->getAttribute(PDO::ATTR_DRIVER_NAME) === 'mysql' ? 'public' : 'dbo'; $tables = $db->getSchema()->getTableNames($schema); foreach ($tables as $table) { echo $table . "\n"; }In this example, we are retrieving all table names in a specific database schema using the getSchema function. We are also using the PDO library to connect to the database. The package library for the PHP DB getSchema function depends on the specific PHP database functions being used (mysqli, PDO, etc.).