yii\db\Command::bindValue PHP Method

bindValue() public method

Binds a value to a parameter.
See also: http://www.php.net/manual/en/function.PDOStatement-bindValue.php
public bindValue ( string | integer $name, mixed $value, integer $dataType = null )
$name string | integer Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form `:name`. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
$value mixed The value to bind to the parameter
$dataType integer SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
    public function bindValue($name, $value, $dataType = null)
    {
        if ($dataType === null) {
            $dataType = $this->db->getSchema()->getPdoType($value);
        }
        $this->_pendingParams[$name] = [$value, $dataType];
        $this->params[$name] = $value;
        return $this;
    }

Usage Example

Esempio n. 1
0
 /**
  * Binds a value to a parameter.
  * @param string|integer $name Parameter identifier. For a prepared statement
  * using named placeholders, this will be a parameter name of
  * the form `:name`. For a prepared statement using question mark
  * placeholders, this will be the 1-indexed position of the parameter.
  * @param mixed $value The value to bind to the parameter
  * @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
  * @return static the current command being executed
  * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
  */
 public function bindValue($name, $value, $dataType = null)
 {
     if ($dataType === null) {
         $dataType = $this->db->getSchema()->getPdoType($value);
     }
     if ($dataType == \PDO::PARAM_BOOL) {
         $dataType = \PDO::PARAM_INT;
     }
     return parent::bindValue($name, $value, $dataType);
 }
All Usage Examples Of yii\db\Command::bindValue