Changing from php 5 to php 7 I must change my queries. Now using PDO.
Is this method sufficient to prevent mysql injection etc?
I connect to the db like this:
$conn = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
my full query is 8 queries joined by union all. My (simplified) query is like this: (there are other cols to be queried, hence the numerous union all)
$query="select * from product_catalogue
where sub_category like ?
union all
select * from product_catalogue
where brand like ?
union all
select * from product_catalogue
where category like ?
union all
select * from product_catalogue
where colour like ?
union all
select * from product_catalogue
where stock_code like ?
union all
select * from product_catalogue
where barcode like ?
union all
select * from product_catalogue
where item_name like ?
union all
select * from product_catalogue
where department like ?";
$input = "%".$input."%";
$stmt = $conn->prepare($query);
$stmt->bindParam(1, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(2, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(3, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(4, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(5, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(6, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(7, $input, PDO::PARAM_STR, 12);
$stmt->bindParam(8, $input, PDO::PARAM_STR, 12);
$stmt->execute();
$data = $stmt->fetchAll();