LIKE和%通配符在Doctrine的findBy *() [英] LIKE and % Wildcard in Doctrine's findBy*()

查看:579
本文介绍了LIKE和%通配符在Doctrine的findBy *()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Doctrine的findBy *()方法编写以下MySQL查询:

  SELECT column_name1,column_name2 FROM table_name 
WHERE column_name3 LIKE'%search_key%';例如,要使用Doctrine从名为ColumnName的列(下面)中提取多行:

/ p>

  $ users = Doctrine :: getTable('User') - > findByColumnName('active'); 

echo $ users [0] - > username;
echo $ users [1] - > username;

我试过:

  $ search_key ='some value'; 
$ users = Doctrine :: getTable('User') - > findByColumnName('%$ search_key%');

echo $ users [0] - > username;
echo $ users [1] - > username;

我没有错误,但没有任何显示。



任何帮助将非常感激。提前感谢。

解决方案

  $ users = Doctrine :: getTable('User') - > createQuery('u')
- > where('column_name3 LIKE?','%search_key%')
- > execute


How do I write the following MySQL query using Doctrine's findBy*() method?:

SELECT column_name1, column_name2 FROM table_name
WHERE column_name3 LIKE '%search_key%';

For Example, to fetch multiple rows from a column named "ColumnName" (below) using Doctrine:

$users = Doctrine::getTable('User')->findByColumnName('active');

echo $users[0]->username;
echo $users[1]->username;

I tried:

$search_key = 'some value';
$users = Doctrine::getTable('User')->findByColumnName('%$search_key%');

    echo $users[0]->username;
    echo $users[1]->username;

and I got no errors, but nothing displayed.

Any assistance will be really appreciated. Thanks in advance.

解决方案

$users = Doctrine::getTable('User')->createQuery('u')
  ->where('column_name3 LIKE ?', '%search_key%')
  ->execute();

这篇关于LIKE和%通配符在Doctrine的findBy *()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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