原则和喜欢查询 [英] Doctrine and LIKE query
本文介绍了原则和喜欢查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有教义的实体:
<?php
/**
* @Entity
* @Table(name="orders")
*/
class Orders {
/** @Id @Column(name="OID",type="integer") @GeneratedValue */
private $id;
/** @Column(name="Product",type="string")*/
private $product;
/** @Column(name="RegCode",type="string")*/
private $reg_code;
/** @Column(name="OrderEmail",type="string")*/
private $email;
}
我需要像这样进行查询:
I need make query like this:
select * from `orders` where `OrderEmail`='some@mail.com' and `Product` LIKE 'My Products%'
我尝试不使用以下方式处理查询:
I try handle query without like:
$em->getRepository("Orders")->findByEmailAndProduct($uname,$product);
但这会出错。为什么?
我可以在没有DQL的情况下执行此查询吗?我想使该查询使用魔术方法 findBy **
But it make error. Why? Can I do this query without DQL? I want make this query use magic methods findBy**
推荐答案
魔术无法实现寻找方法。尝试使用查询生成器:
This is not possible with the magic find methods. Try using the query builder:
$result = $em->getRepository("Orders")->createQueryBuilder('o')
->where('o.OrderEmail = :email')
->andWhere('o.Product LIKE :product')
->setParameter('email', 'some@mail.com')
->setParameter('product', 'My Products%')
->getQuery()
->getResult();
这篇关于原则和喜欢查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文