ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

MySQL list columns names from table php pdo

$pdo = new PDO("mysql:host=localhost", "root", "");
 
$stmtnTable = $pdo->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ' database name ' AND TABLE_NAME = ' table name '");
 
$tables_name = $stmtnTable->fetchAll(PDO::FETCH_COLUMN);
 
foreach($tables_name as $columnsName){
 
  echo $columnsName, '<br>';

}