如果直接写
$sql = "... to_tsquery( 'word_1 | word_2' )";
有效,但如何在PDO准备好的声明中使用这种语法?
这是什么语法:
$sql = " ... to_tsquery( :word_1 | :word_2 ) "; //this is incorrect
$sth = $db->prepare( $sql );
$sth->execute(
array( ':word_1'=>"word_1", ':word_2'=>"word_2" )
);
答案 0 :(得分:0)
像这样:
denis=# select to_tsquery('(foo | bar) & baz');
to_tsquery
---------------------------
( 'foo' | 'bar' ) & 'baz'
(1 row)
denis=# select (to_tsquery('foo') || to_tsquery('bar')) && to_tsquery('baz');
?column?
---------------------------
( 'foo' | 'bar' ) & 'baz'
(1 row)