I want to create a search function from MySQL database using PHP. I tried to extract datas which is partially matched with the string that users entered with the following code:
$pdo = new PDO('mysql:host=localhost;dbname=tweet;charset=utf8;', 'admin', 'password');
$stmt = $pdo->prepare("SELECT * FROM tweets where contents like '%?%'");
if ($stmt->execute([$_REQUEST['search']])) {
foreach ($stmt as $row) {
echo $row['data'];
}
However, it doesn't show anything even the string is same as the data. Any solutions?