2

如果直接写

$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" )
);
4

1 回答 1

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)
于 2013-05-13T13:47:21.273 回答