I think the REGEX operator is correctly spelled REGEXP. If you just want to find out, if the column contains a value, you should consider using LIKE and the wildcard char %.
To avoid painful quoting the mysql reference manual suggest binding the value like this: $sth = $dbh->prepare ("select name from toolbox where name LIKE CONCAT('%', ? ,'%')"); $sth->execute ($name); Hendrik Am Do, 13.11.2008, 15:50, schrieb Deviloper: > > > ---------- Ursprüngliche Nachricht ---------- > Von: Deviloper <[EMAIL PROTECTED]> > An: [EMAIL PROTECTED] > Datum: 13. November 2008 at 15:41 > Betreff: How to write a (My)SQL statement with REGEX / RLIKE containing a > scalar variable? > > I have a SQL-Statement with a Regular Expression and I want to use a > scalar in that expression: (Looking for something like "$tool =~ > m/\Q$x\E/" ) > > #Find tools with xxxxxx in the name: > $dbh->prepare ("SELECT name FROM toolbox WHERE name REGEX '$x'"); > #or > $dbh->prepare ("SELECT name FROM toolbox WHERE name RLIKE '$x'"); > $sth->execute(); > my ($name_of_tool) = $sth->fetchrow_array; > $sth->finish(); > > (Don´t need to mention that this don´t work as expected, but I don´t > know how to escape it the right way. ^^) > > Thanks, > B.