我想用DBAL理论来获得字段名。
这是我的sql查询:
$em = $this->getDoctrine()->getManager();
$connection = $em->getConnection();
$listcontact = $connection->prepare("select * from contact");
$listcontact->execute();如何使用DBAL获取字段的名称
发布于 2016-01-18 15:58:46
您可以使用Doctrine的架构管理器:
// 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
https://stackoverflow.com/questions/34858227
复制相似问题