Hi everybody.
Currently it is not possible to clear the PDOStatement params, so it would
be useful to add a method for it.
Why? PDOStatement::execute
admits the $input_parameters
argument, but
all values are passed as PDO::PARAM_STR
and that hit a performance
problem at MariaDB.
The fix it is to be able to call the clearParams
first and bindValue
later for each param.
I don't have permissions to create RFC :(
Hi Juanra,
Thanks for sharing your interest in improving PHP. Your proposal is very
unclear at the moment. What do you think this function should do? Why can't
you just recreate the prepared statement? What performance hit are you
talking about?
I don't see how such a function would be useful, but I hope you can explain
your use case and its reasoning.
Regards,
Kamil
Hello Kamil, thanks you for your reply.
I am going to enumerate the answers.
-
PDOStatement::clearParams
should reset the statament params (
https://github.com/php/php-src/blob/31c74aaeebf3af3c87e3981703f9f775c65600b9/ext/pdo/pdo_stmt.c#L406-L410
). - Recreate the prepared statement is very cost.
- SQL engine is choosing bad the search index because I am passing a param
as string insteadof integer.
If you call PDOStatement::execute
without params, the statement will use
the last params. Don't to clear the last params can be a problem. For
example:
$pdo->bindValue("id1", 1, PDO::PARAM_INT);
$pdo->bindValue("id2", 2, PDO::PARAM_INT);
$pdo->execute(); // id1 => 1, id2 => 2
$pdo->bindValue("id2", 3, PDO::PARAM_INT);
$pdo->execute(); // id1 => 1, id2 => 3
If you call $pdo->clearParams();
before of each execute
, then it will
throw a fatal error because it won't use the previous params.
The main idea is to overwrite the PDOStatement::execute
method, using a
custom class (PDO::ATTR_STATEMENT_CLASS
) for bind values individually
with their types (bindValue
), but firstly I need call clearParams
.
El mar., 4 may. 2021 12:18, Kamil Tekiela tekiela246@gmail.com escribió:
Hi Juanra,
Thanks for sharing your interest in improving PHP. Your proposal is very
unclear at the moment. What do you think this function should do? Why can't
you just recreate the prepared statement? What performance hit are you
talking about?
I don't see how such a function would be useful, but I hope you can
explain your use case and its reasoning.Regards,
Kamil