I'm having an issue trying to bind and execute a PDO statement using PHP and a REGEXP for a SQLite database. I have a column containing string words separated by spaces, and I am using the following REGEXP (?<!\S)WORD(?!\S)
to match complete words that are surrounded by white space. The following SQL query works when I run in SQLite studio and gives me the desired results:
SELECT * FROM Questions WHERE Tags REGEXP '(?<!\S)WORD(?!\S)'
However, when I try to use it in a PDO statement, it keeps failing. So far I have tried:
$sql = "SELECT * FROM Questions WHERE Tags REGEXP :tags";
$tags = '(?<!\S)WORD(?!\S)';
$statement = $db -> prepare($sql);
$statement -> bindParam(':tags', $tags);
and I have also tried escaping backslashes as well as running the query directly without using any prepared statements and simply using a known working query and it still seems to fail. Ex w/o binds:
$sql = "SELECT * FROM Questions WHERE Tags REGEXP '(?<!\S)TAG(?!\S)'";
$statement = $db -> query($sql);
However that doesn't seem to work with the REGEXP either. If I change it to a simple SELECT * from the entire table or any non-REGEXP query everything seems to work fine until I add in those REGEXPs. I'm pretty new to PHP so I'm not entirely sure what is going on here or where to look. Any help would be appreciated!