fetch_fields() 使用 DBAL 学说

fetch_fields() using DBAL doctrine

我想使用doctrine DBAL获取字段名

这是我的 sql 查询:

 $em = $this->getDoctrine()->getManager();
 $connection = $em->getConnection();
  $listcontact = $connection->prepare("select * from contact");
  $listcontact->execute();

如何使用 DBAL 获取字段名称

您可以使用 Doctrine DBAL 的模式管理器:

// Get schema manager : 
$sm = $connection->getSchemaManager();
// Get fields list from table 'contact' :
$columns = $sm->listTableColumns('contact');
// Loop over the array to get names and other properties : 
foreach ($columns as $column) {
    echo $column->getName() . ': ' . $column->getType() . "\n";
}

模式管理器的完整文档在这里:http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html