加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

doctrine2本机查询更新语句

发布时间:2020-12-15 04:55:05 所属栏目:Java 来源:网络整理
导读:如何在Doctrine 2中执行本机sql查询,执行更新语句? EntityManager上的createNativeQuery方法需要第二个参数(ResultSetMapping)才能将结果集映射到Objects. 但是在更新(或插入,设置或……)时,没有映射的结果集. 传递null或只是新的ResultSetMapping(),会出错
如何在Doctrine 2中执行本机sql查询,执行更新语句?
EntityManager上的createNativeQuery方法需要第二个参数(ResultSetMapping)才能将结果集映射到Objects.

但是在更新(或插入,设置或……)时,没有映射的结果集.
传递null或只是新的ResultSetMapping(),会出错.

是否仅支持本机sql的选择查询?

解决方法

基本上同上,用faken,

这来自docs:

If you want to execute DELETE,UPDATE or INSERT statements the Native
SQL API cannot be used and will probably throw errors. Use
EntityManager#getConnection() to access the native database connection
and call the executeUpdate() method for these queries.

一个使用注意事项是可以从EntityManager检索连接对象:

$conn = $entityManager->getConnection();
$rowsAffected = $conn->executeUpdate($sql,$params,$types);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读