considering SQL injections and some other features, I'm shifting from mysqli to PDO. But first of all, I want to convert all functions that I already had in my mysqli to PDO, so that I can move on to prepared statements and further security options.
What I currently have is a keyword search in one column. What I want to do is searching for the same keyword in multiple columns of the same table using PDO.
Here is the code I currently have:
$keywordfromform = $_GET["keyword"];
$keyword = "%$keywordfromform%";
$sql = 'SELECT * FROM table
WHERE title LIKE ?';
$stmt = $pdo->prepare($sql);
$stmt->execute([$keyword]);
$entries = $stmt->fetchAll();
In mysqli, I just used WHERE CONCAT_WS(' ', title, author, text, year)
, but with PDO it's not working. I considered using WHERE title LIKE ? OR author LIKE ? OR text LIKE ? OR year LIKE ?
, but this doesn't work either. I suspect that I need to use some sort of $stmt->bind_param()
. However, there are mainly mysqli oriented questions and answers online and I don't get it running.
I would appreciate your help!