Changing from php 5 to php 7 I must change my queries. Now using PDO.
I connect to the db like this:
$conn = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
my full query is 6 queries joined by union all. My (simplified) query is like this:
$query="select * from table
where sub_category like '%$input%'
where input is kettles, for example
my script gets the input value like this:
$input = $_GET['input'];
If I sanitise it using
$input = $conn->quote($_GET['input']);
the value becomes 'kettles' (surrounded with single quotes), and my query returns 0 results.
I process the query thus:
$stmt = $conn->prepare($query);
$stmt->execute(array("%$query%"));
$data = $stmt->fetchAll();
So; is PDO sanitising it and if not, how do I do it?