yii\db\Command::bindParam PHP Method

bindParam() public method

Binds a parameter to the SQL statement to be executed.
See also: http://www.php.net/manual/en/function.PDOStatement-bindParam.php
public bindParam ( string | integer $name, mixed &$value, integer $dataType = null, integer $length = null, mixed $driverOptions = 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 PHP variable to bind to the SQL statement parameter (passed by reference)
$dataType integer SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
$length integer length of the data type
$driverOptions mixed the driver-specific options
    public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null)
    {
        $this->prepare();
        if ($dataType === null) {
            $dataType = $this->db->getSchema()->getPdoType($value);
        }
        if ($length === null) {
            $this->pdoStatement->bindParam($name, $value, $dataType);
        } elseif ($driverOptions === null) {
            $this->pdoStatement->bindParam($name, $value, $dataType, $length);
        } else {
            $this->pdoStatement->bindParam($name, $value, $dataType, $length, $driverOptions);
        }
        $this->params[$name] =& $value;
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * Binds a parameter to the SQL statement to be executed.
  * @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 Name of the PHP variable to bind to the SQL statement parameter
  * @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
  * @param integer $length length of the data type
  * @param mixed $driverOptions the driver-specific options
  * @return static the current command being executed
  * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
  */
 public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null)
 {
     if ($dataType == \PDO::PARAM_BOOL) {
         $dataType = \PDO::PARAM_INT;
     }
     return parent::bindParam($name, $value, $dataType, $length, $driverOptions);
 }
All Usage Examples Of yii\db\Command::bindParam