Symfony2 (doctrine2) native sql insert

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

How to insert data in symfony2 doctrine2 on native sql?

My query

insert into propriedades (id,name,descripcion,num_lote,cod_imovel,imovel,convenio,proprietar,cpf,area_ha,perimetro,location,centro) VALUES (nextval('propriedades_id_seq'),'?','?','?','?','?','?','?','?','?','?',ST_GeomFromKML('<Polygon><outerBoundaryIs><LinearRing><coordinates>".$terra['coordinates']."</coordinates></LinearRing></outerBoundaryIs></Polygon>'),ST_Centroid(ST_GeomFromKML('<Polygon><outerBoundaryIs><LinearRing><coordinates>".$terra['coordinates']."</coordinates></LinearRing></outerBoundaryIs></Polygon>'))) 

回答1:

You have to use $conn->insert('table', $dataArray);. See documentation



回答2:

Usually you do not use what you call native sql in a symfony 2 project but the high level Doctrine ORM layer.

However there is a doctrine dbal layer which enables e.g. mysql queries instead of DQL. Here is the reference

http://symfony.com/doc/2.0/cookbook/doctrine/dbal.html



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!