在Doctrine DBAL Query Builder上缺少insert()方法 [英] Missing insert() method on Doctrine DBAL Query Builder

查看:386
本文介绍了在Doctrine DBAL Query Builder上缺少insert()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我有一段时间,我在这里缺少一些小东西;我在Dotrine DBAL 2.2.x / 2.3上的 QueryBuilder 组件上使用 insert() .x。



我做了一些调查,这里是 DBAL Documantation中的QueryBuilder页面


\Doctrine\DBAL\Query\QueryBuilder支持构建SELECT,INSERT,UPDATE和DELETE查询。您正在构建哪种查询取决于您使用的方法。


进一步解释代码示例,使我可以简单地做:

  $ builder = $ connection-> createQueryBuilder(); 
$ result = $ builder
- > insert('table_name')
// ...

要在插入模式中使用查询构建器。除非我从PHP处获得投诉:


致命错误:调用未定义的方法Doctrine\\对于


$ b < .com / doctrine / dbal / blob / 2.3 / lib / Doctrine / DBAL / Query / QueryBuilder.phprel =nofollow> QueryBuilder.php源代码



我没有参考任何方法 insert(...),没有类继承这个,没有特征添加到 QueryBuilder 可能会暴露插入机制。另外我在顶部看到这个权限:

  / *查询类型。 * / 
const SELECT = 0;
const DELETE = 1;
const UPDATE = 2;

没有插入查询类型;然而,对于 execute(),有一个有趣的方法评论:

  ** 
*使用绑定参数及其类型执行此查询。
*
*为插入,更新和删除语句使用{@see Connection :: executeQuery}用于select语句和{@see Connection :: executeUpdate}
*。
*
* @return mixed
* /



底线:



这是一个拥有100名维护者的大型项目,我更有可能在这里找到我的解释嫌疑人,而不是对许多版本的基础知识进行修复,但是我不能为我的生活找出我所缺少的东西。 请帮助我看到明显的。


解决方案

这取决于你的版本。从v2.5.0-BETA3开始添加插入。



Viz https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Query/QueryBuilder.php #L563
提交



您可以决定更新包版本或检查此替代解决方案


I feel like I'm having a moment where I'm missing something small here; I've been having issues using the insert() method on the QueryBuilder component on Dotrine DBAL 2.2.x / 2.3.x.

I did some investigation and here's the snippet from the QueryBuilder page from the DBAL Documantation

The \Doctrine\DBAL\Query\QueryBuilder supports building SELECT, INSERT, UPDATE and DELETE queries. Which sort of query you are building depends on the methods you are using.

It goes on further to explain code examples, such that I can simply do:

$builder = $connection->createQueryBuilder();
$result = $builder
    ->insert('table_name')
    // ...

To use the query builder in Insert Mode. Except when I do I get a complaint here from PHP:

Fatal error: Call to undefined method Doctrine\DBAL\Query\QueryBuilder::insert()

On further inspection of The QueryBuilder.php Source Code

I see no reference to any method insert(...), no class to inherit this from, no traits added to the QueryBuilder that could expose the insert mechanism. In addition I see this right at the top:

/* The query types. */
const SELECT = 0;
const DELETE = 1;
const UPDATE = 2;

There's no insert query type; there is however this interesting method comment for execute():

/**
 * Execute this query using the bound parameters and their types.
 *
 * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
 * for insert, update and delete statements.
 *
 * @return mixed
 */

Bottom Line:

This is a massive project with 100's of maintainers, I'm more likely to find my interpretation suspect here than a screwup on something so fundamental over numerous versions, but I cannot for the life of me figure out what I'm missing. Please help me see the obvious.

解决方案

It depends on your version. Insert has been added since v2.5.0-BETA3.

Viz https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Query/QueryBuilder.php#L563 and commit

You can decide to update package version or check this alternative solution

这篇关于在Doctrine DBAL Query Builder上缺少insert()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆