我想使用doctrine DBAL
获取字段名称这是我的SQL查询:
$em = $this->getDoctrine()->getManager();
$connection = $em->getConnection();
$listcontact = $connection->prepare("select * from contact");
$listcontact->execute();
如何使用DBAL获取字段名称
答案 0 :(得分:2)
您可以使用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