PHP/PDO:SQl查找包含字符串值的行

waw*_*los -5 php mysql sql pdo

我尝试发出一个请求来查找包含特定字符串值的行.

这是我的代码的摘录:

// Getting motscles value
        $motscles = $_POST['motscles'];

        // Prepare a second SQL request to get all annonces posted by the user
        $result2=$connexion->prepare("select * from annonces where titre LIKE = '%".$motscles."%' ");
Run Code Online (Sandbox Code Playgroud)

我没有结果,我认为我的要求很糟糕..

med*_*eda 6

另外@abhik's回答如果你准备好了

$stmt=$connexion->prepare('select * from annonces where titre LIKE ?');
$result2=$stmt->execute(array('%'.$motscles.'%'));
Run Code Online (Sandbox Code Playgroud)