We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

executePrepared what's $dataTypes?

Hi, I'm trying to use executePrepared from Phalcon\Db\Adapter\Pdo\Mysql but I have no idea what the third parameter $dataTypes is supposed to be. Documentation just ignores this third parameter but it's not optional!

public PDOStatement executePrepared (PDOStatement $statement, array $placeholders, array $dataTypes) inherited from Phalcon\Db\Adapter\Pdo



98.9k
Accepted
answer

You don't need to use that method directly, Phalcon\Db automatically prepares the statements for you using 'query' and 'execute':

$result = $db->query("SELECT * FROM x WHERE id = ?", array(100));
$db->execute("INSERT INTO x VALUES(?, ?)", array(100, 'some value'));
edited Nov '15

Is this still valid for Phalcon 2.0.8? We should just avioid prepared statements since the framework is doing it by default?

Nevertheless, the documentation is then wrong by an example:

$statement = $db->prepare('SELECT * FROM robots WHERE name = :name');
$result = $connection->executePrepared($statement, array('name' => 'Voltron'));

https://docs.phalcon.io/en/latest/api/Phalcon_Db_Adapter_Pdo_Mysql.html

Automatic bound parameters are only being made by Phalcon for INSERT/UPDATE/DELETE operations, Query operations require attention by the developer.