简体   繁体   English

如何在REGEXP中使用多个关键字?

[英]How can I use multiple keywords with REGEXP?

I have a query like so 我有这样的查询

SELECT name FROM users WHERE interests REGEXP :interests

since interests are varied, I have an array of submitted interests that I'm imploding to reach the database like golf|soccer|tennis . 由于兴趣各不相同,因此我需要提交一系列感兴趣的兴趣,以便像golf|soccer|tennis到达数据库。 I'm then using that array to replace :interests but MYSQL is throwing an error: 然后,我使用该数组替换:interests,但是MYSQL抛出错误:

SQLSTATE[HY000]: General error: property queryString is read only SQLSTATE [HY000]:常规错误:属性queryString是只读的

Idealy the query should read: 理想情况下,查询应显示为:

SELECT name FROM users WHERE interests REGEXP golf|tennis|chess

I'm using PDO, what's the workaround I can use? 我正在使用PDO,可以使用的解决方法是什么?

EDIT: This is the other php code, as requested 编辑:这是根据要求的其他PHP代码

$keys = implode('|', array_filter($f3->get('keywords')));

//query the database, looking for matches in the users table.
$q = $db->prepare("SELECT * FROM users WHERE interests REGEXP :keywords");
$q->execute(array(':keywords' => $keys));
$q->setFetchMode(PDO::FETCH_ASSOC);
$q->fetchAll();
$result = $q->fetchAll();

我回溯了我的步骤,并将结果分配给一个变量,一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM