Doctrine\DBAL\Statement::bindValue PHP Method

bindValue() public method

The value can optionally be bound with a PDO binding type or a DBAL mapping type. If bound with a DBAL mapping type, the binding type is derived from the mapping type and the value undergoes the conversion routines of the mapping type before being bound.
public bindValue ( string $name, mixed $value, mixed $type = null ) : boolean
$name string The name or position of the parameter.
$value mixed The value of the parameter.
$type mixed Either a PDO binding type or a DBAL mapping type name or instance.
return boolean TRUE on success, FALSE on failure.
    public function bindValue($name, $value, $type = null)
    {
        $this->params[$name] = $value;
        $this->types[$name] = $type;
        if ($type !== null) {
            if (is_string($type)) {
                $type = Type::getType($type);
            }
            if ($type instanceof Type) {
                $value = $type->convertToDatabaseValue($value, $this->platform);
                $bindingType = $type->getBindingType();
            } else {
                $bindingType = $type;
                // PDO::PARAM_* constants
            }
            return $this->stmt->bindValue($name, $value, $bindingType);
        } else {
            return $this->stmt->bindValue($name, $value);
        }
    }

Usage Example

 protected function write(array $record)
 {
     if (!$this->initialized) {
         $this->initialize();
     }
     $this->statement->bindValue('channel', $record['channel'], Type::STRING);
     $this->statement->bindValue('level', $record['level'], Type::INTEGER);
     $this->statement->bindValue('level_name', $record['level_name'], Type::STRING);
     $this->statement->bindValue('message', $record['message'], Type::TEXT);
     $this->statement->bindValue('context', $record['context'], Type::TARRAY);
     $this->statement->bindValue('extra', $record['extra'], Type::TARRAY);
     $this->statement->bindValue('datetime', $record['datetime'], Type::DATETIME);
     $this->statement->execute();
 }
All Usage Examples Of Doctrine\DBAL\Statement::bindValue