It is not possible to use parameters to describe column or table names in PDO.
For instance:
CREATE TABLE ? (id INT(6) PRIMARY KEY AUTO_INCREMENT, ...)
How about using a temporary table to handle malicious data and then feeding it back into the statement ?
$hex = bin2hex(random_bytes(8));
$stmt = $db->prepare('INSERT INTO tmpdata (value,hex) VALUES (:val,:hex)');
$stmt->execute(array(
":val" => $_POST['catname'],
":hex" => $hex
));
$stmt = $db->prepare('SELECT value FROM tmpdata WHERE hex=?');
$stmt->execute(array($hex));
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
$cleaned_value = $row[0]['value'];
Is this an acceptable and more importantly safe way to feed parameters into PDO for column and table names ?