yii\db\Command::bindValues PHP Method

bindValues() public method

This is similar to Command::bindValue except that it binds multiple values at a time. Note that the SQL data type of each value is determined by its PHP type.
public bindValues ( array $values )
$values array the values to be bound. This must be given in terms of an associative array with array keys being the parameter names, and array values the corresponding parameter values, e.g. `[':name' => 'John', ':age' => 25]`. By default, the PDO type of each value is determined by its PHP type. You may explicitly specify the PDO type by using an array: `[value, type]`, e.g. `[':name' => 'John', ':profile' => [$profile, \PDO::PARAM_LOB]]`.
    public function bindValues($values)
    {
        if (empty($values)) {
            return $this;
        }
        $schema = $this->db->getSchema();
        foreach ($values as $name => $value) {
            if (is_array($value)) {
                $this->_pendingParams[$name] = $value;
                $this->params[$name] = $value[0];
            } else {
                $type = $schema->getPdoType($value);
                $this->_pendingParams[$name] = [$value, $type];
                $this->params[$name] = $value;
            }
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * Creates a command for execution.
  * @param string $sql the SQL statement to be executed
  * @param array $params the parameters to be bound to the SQL statement
  * @return Command the DB command
  */
 public function createCommand($sql = null, $params = [])
 {
     $command = new Command(['db' => $this, 'sql' => $sql]);
     return $command->bindValues($params);
 }
All Usage Examples Of yii\db\Command::bindValues