Doctrine\DBAL\Connection::_bindTypedValues PHP Method

_bindTypedValues() private method

Binds a set of parameters, some or all of which are typed with a PDO binding type or DBAL mapping type, to a given statement.
private _bindTypedValues ( Doctrine\DBAL\Driver\Statement $stmt, array $params, array $types ) : void
$stmt Doctrine\DBAL\Driver\Statement The statement to bind the values to.
$params array The map/list of named/positional parameters.
$types array The parameter types (PDO binding types or DBAL mapping types).
return void
    private function _bindTypedValues($stmt, array $params, array $types)
    {
        // Check whether parameters are positional or named. Mixing is not allowed, just like in PDO.
        if (is_int(key($params))) {
            // Positional parameters
            $typeOffset = array_key_exists(0, $types) ? -1 : 0;
            $bindIndex = 1;
            foreach ($params as $value) {
                $typeIndex = $bindIndex + $typeOffset;
                if (isset($types[$typeIndex])) {
                    $type = $types[$typeIndex];
                    list($value, $bindingType) = $this->getBindingInfo($value, $type);
                    $stmt->bindValue($bindIndex, $value, $bindingType);
                } else {
                    $stmt->bindValue($bindIndex, $value);
                }
                ++$bindIndex;
            }
        } else {
            // Named parameters
            foreach ($params as $name => $value) {
                if (isset($types[$name])) {
                    $type = $types[$name];
                    list($value, $bindingType) = $this->getBindingInfo($value, $type);
                    $stmt->bindValue($name, $value, $bindingType);
                } else {
                    $stmt->bindValue($name, $value);
                }
            }
        }
    }