yii\db\Query::scalar PHP Method

scalar() public method

The value returned will be the first column in the first row of the query results.
public scalar ( Connection $db = null ) : string | null | false
$db Connection the database connection used to generate the SQL statement. If this parameter is not given, the `db` application component will be used.
return string | null | false the value of the first column in the first row of the query result. False is returned if the query result is empty.
    public function scalar($db = null)
    {
        if ($this->emulateExecution) {
            return null;
        }
        return $this->createCommand($db)->queryScalar();
    }

Usage Example

Example #1
0
 public function encodePassword($password)
 {
     $query_pass = new Query();
     $exppass = new Expression('password(:password)', [':password' => $password]);
     $query_pass->select(['password' => $exppass]);
     $hash = $query_pass->scalar();
     //        var_dump($hash);die;
     return $hash;
 }
All Usage Examples Of yii\db\Query::scalar