ManaPHP\Db::_executePrepared PHP Method

_executePrepared() protected method

Executes a prepared statement binding. This function uses integer indexes starting from zero $statement = $db->prepare('SELECT * FROM robots WHERE name = :name'); $result = $connection->executePrepared($statement, array('name' => 'mana'));
protected _executePrepared ( PDOStatement $statement, array $bind ) : PDOStatement
$statement PDOStatement
$bind array
return PDOStatement
    protected function _executePrepared($statement, $bind)
    {
        foreach ($bind as $parameter => $value) {
            if (is_string($value)) {
                $type = \PDO::PARAM_STR;
            } elseif (is_int($value)) {
                $type = \PDO::PARAM_INT;
            } elseif (is_bool($value)) {
                $type = \PDO::PARAM_BOOL;
            } elseif ($value === null) {
                $type = \PDO::PARAM_NULL;
            } else {
                throw new DbException('The `:type` type of `:parameter` parameter is not support', ['parameter' => $parameter, 'type' => gettype($value)]);
            }
            if (is_int($parameter)) {
                $statement->bindValue($parameter + 1, $value, $type);
            } else {
                if ($parameter[0] === ':') {
                    throw new DbException('Bind does not require started with `:` for `:parameter` parameter', ['parameter' => $parameter]);
                }
                $statement->bindValue(':' . $parameter, $value, $type);
            }
        }
        $statement->execute();
        return $statement;
    }