简体   繁体   中英

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 . I'm then using that array to replace :interests but MYSQL is throwing an error:

SQLSTATE[HY000]: General error: property queryString is read only

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?

EDIT: This is the other php code, as requested

$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();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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