Symfony2 (doctrine2) native sql insert

2019-07-08 19:50发布

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>')))

2条回答
不美不萌又怎样
2楼-- · 2019-07-08 20:28

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

查看更多
手持菜刀,她持情操
3楼-- · 2019-07-08 20:34

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

查看更多
登录 后发表回答