Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



84.5k
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.phalconphp.com/en/latest/api/Phalcon%5Db%5Adapter%5Pdo%5Mysql.html

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