I'm looking to use the Doctrine DBAL function executeQuery as follows:
$conn = DBAL\DriverManager::getConnection($connectionParams, $config);
$sql = "SELECT count(*) FROM clients WHERE client_id = :id";
$results = $conn->executeQuery($sql, ['id' => 'foo'], ['id' => \PDO::PARAM_STR]);
var_dump($results->fetchAll());
var_dump($results->rowCount());
Which works fine returning:
array (size=1)
0 =>
array (size=1)
'count(*)' => string '1' (length=1)
int 1
However the code also works using the following lines (where the types parameters is declared incorrectly or not declared at all):
$results = $conn->executeQuery($sql, ['id' => 'foo'], ['id' => \PDO::PARAM_INT]);
$results = $conn->executeQuery($sql, ['id' => 'foo'], ['notatag' => \PDO::PARAM_STR]);
$results = $conn->executeQuery($sql, ['id' => 'foo']);
Suggesting the declaring the bound variable data type isn't being used, raising concerns as to if this is protected against SQL injection.
Am I doing something wrong here? How can I be sure my code is secure?